Advertisement
EESweetieBot

[EE] Bot.lua

Jul 23rd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. --< import / using >--
  2.     --[[ NOTE: I only did this because I'm lazy af ]]--
  3.     import ('System.IO') -- Imported for File reading and writing
  4. --< import / using >--
  5.  
  6. --< Init Function >--
  7.     -- Why this you might ask?... wait, uh.
  8.     function init()
  9.         local a = File.ReadAllLines("Lua\\login.txt") -- A sample of System.IO on lua.
  10.         Console:WriteLine("Console initialized!.. Connecting to Server")
  11.         Connect:ToServer(a[0],a[1])
  12.         Console:WriteLine("Connected to Server... connecting to the World")
  13.         Connect:ToEE(a[2])
  14.         Bot:Send("init")
  15.     end
  16. --< Init Function >--
  17.  
  18. --< Global Variables >--
  19.     Players = {}
  20.     BotId = -1
  21.     Owner = ""
  22.     BotPrefix = "[Melody]: "
  23. --< Global Variables >--
  24.  
  25. --< Global Functions >--
  26.     function Say(msg)
  27.         Bot:Send("say", BotPrefix..msg)
  28.     end
  29.     function PM(plr, msg)
  30.         Bot:Send("say", "/pm "..plr.." "..BotPrefix..msg)
  31.     end
  32.     function Cmd(msg)
  33.         Bot:Send("say", "/"..msg)
  34.     end
  35. --< Global Functions >--
  36.  
  37. --< onMessage Voids >--
  38.     function onInit(msg)
  39.         BlockWorld:HandleMessage(msg)
  40.         BotId = msg:GetInt(5)
  41.         Owner = msg:GetString(0)
  42.         Say("Sucessfully Connected!")
  43.         Bot:Send("init2")
  44.     end
  45.  
  46.     function onAdd(msg)
  47.         local username = msg:GetString(1)
  48.         local userid = msg:GetInt(0)
  49.         if Players[userid] == nil then
  50.             Players[userid] = username
  51.             Say(username.." joined the world!")
  52.         end
  53.     end
  54.  
  55.     function onLeft(msg)
  56.         local userid = msg:GetInt(1)
  57.         if Players[userid] ~= nil then
  58.             local username = Players[userid]
  59.             Players[userid] = nil
  60.             Say(username.." left the world!")
  61.         end
  62.     end
  63.  
  64.     function onSay(msg)
  65.         local userid = msg:GetInt(0)
  66.         local message = msg:GetString(1)
  67.         if Players[userid] == nil then
  68.             return
  69.         end
  70.         local username = Players[userid]
  71.         local isCommand = false
  72.         local stringspl = {}
  73.         --< Check if message is command >--
  74.             local prefixes = {
  75.                 ".","!","~"
  76.             }
  77.             for i,v in pairs(prefixes) do
  78.                 if string.sub(message, 1, 1) == v then
  79.                     isCommand = true
  80.                     for word in string.sub(message, 2,-1):gmatch("%w+") do table.insert(stringspl, word) end
  81.                     break
  82.                 end
  83.             end
  84.         --< Check if message is command >--
  85.         if isCommand then
  86.             if stringspl[1] == "test" then
  87.                 Say("It's working!")
  88.             end
  89.         end
  90.     end
  91. --< onMessage Voids >--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement