micro_chatroom serie's
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

micro_chatroom serie's

Started by plop, 16 July, 2004, 20:02:33

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

plop

as i just made version 3 of this bot it seems a nice idea 2 me 2 place them all in 1 topic.

version 1:
-- really lame chat room bot
-- by plop

Bot = "Chat_room"

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   if(strsub(data, 1, 4) == "$To:") then
      local s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if whoTo == Bot then 
         data=strsub(data,1,strlen(data)-1) 
         local s,e,txt = strfind(data, "%$(%b<>.+)")
         if txt then
            SendPmToAll(Bot, txt.."|")
         end
      end
   end
end

version 2:
---------------------------------------
-- V 1
-- really lame chat room bot
----
-- V 2
-- doesn't repeat 2 the sender
-- doesn't show botname on the pm's
---------------------------------------
-- by plop        http://www.plop.nl --
---------------------------------------

Bot = "Chat_room"

tUsers = {}

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   if tUsers[user.sName] == nil then
      tUsers[user.sName] = 1
   end
   if(strsub(data, 1, 4) == "$To:") then
      local s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if whoTo == Bot then 
         data=strsub(data,1,strlen(data)-1) 
         local s,e,txt = strfind(data, "%$(%b<>.+)")
         local usr
         if txt then
            for a,b in tUsers do
               if a ~= user.sName then
                  usr = GetItemByName(a)
                  if usr then
                     usr:SendData("$To: "..usr.sName.." From: "..Bot.." $"..txt.."|")
                  else
                     tUsers[a] = nil
                  end
               end
            end
         end
      end
   end
end

function OpConnected(user)
   if tUsers[user.sName] == nil then
      tUsers[user.sName] = 1
   end
end

NewUserConnected = OpConnected

function OpDisconnected(user)
   if tUsers[user.sName] then
      tUsers[user.sName] = nil
   end
end

UserDisconnected = OpDisconnected

and version 3:
---------------------------------------
-- V 1
-- really lame chat room bot
----
-- V 2
-- doesn't repeat 2 the sender
-- doesn't show botname on the pm's
----
-- V3 
-- added a level system
-- every level has it's own room
-- 1 level can read all
---------------------------------------
-- by plop        http://www.plop.nl --
---------------------------------------

Bot = "_room" -- name of the level is attached 2 the name

tUsers = {}
tBot = {}
trBot = {}
tLevels = {
   [0] = 1,
   [1] = 1,
   [2] =1
}
-- the next level can read all chats
iMaster = 0


function Main()
   for a,b in tLevels do   
      tUsers[a] = {}
      tBot[a]=GetProfileName(a)..Bot
      trBot[GetProfileName(a)..Bot] = a
      frmHub:RegBot(tBot[a])
   end
end

function OnExit()
   for a,b in tBot do
      frmHub:UnregBot(b)
   end
end

function DataArrival(user, data)
   if tUsers[user.iProfile] == nil then
      tUsers[user.iProfile] = {}
   end
   if tUsers[user.iProfile][user.sName] == nil then
      tUsers[user.iProfile][user.sName] = 1
   end
   if(strsub(data, 1, 4) == "$To:") then
      local s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if trBot[whoTo] then 
         if user.iProfile == trBot[whoTo] or user.iProfile == iMaster then
            data=strsub(data,1,strlen(data)-1) 
            local s,e,txt = strfind(data, "%$(%b<>.+)")
            local usr
            local t = trBot[whoTo]
            if txt then
               for a,b in tUsers[t] do
                  if a ~= user.sName then
                     usr = GetItemByName(a)
                     if usr then
                        usr:SendData("$To: "..usr.sName.." From: "..tBot[t].." $"..txt.."|")
                     else
                        tUsers[t][a] = nil
                     end
                  end
               end
               for a,b in tUsers[iMaster] do
                  if a ~= user.sName then
                     usr = GetItemByName(a)
                     if usr then
                        usr:SendData("$To: "..usr.sName.." From: "..tBot[t].." $"..txt.."|")
                     else
                        tUsers[iMaster][a] = nil
                     end
                  end
               end
            end
         else
            user:SendPM(tBot[trBot[whoTo]], "You may not acces this chat room!|")
            return 1
         end
      end
   end
end

function OpConnected(user)
   if tUsers[user.iProfile] == nil then
      tUsers[user.iProfile] = {}
   end
   if tUsers[user.iProfile][user.sName] == nil then
      tUsers[user.iProfile][user.sName] = 1
   end
end

NewUserConnected = OpConnected

function OpDisconnected(user)
   if tUsers[user.iProfile] == nil then
      tUsers[user.iProfile] = {}
   end
   if tUsers[user.iProfile] then
      if tUsers[user.iProfile][user.sName] then
         tUsers[user.iProfile][user.sName] = nil
      end
   end
end

UserDisconnected = OpDisconnected

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<


SMF spam blocked by CleanTalk