diff --git a/src/main.lua b/src/main.lua index f5ba4a9..66f85c3 100644 --- a/src/main.lua +++ b/src/main.lua @@ -213,6 +213,7 @@ local commands=require('./modules/commands.lua') local prefix = ',' local client = discordia.Client() _G.client = client +_G.locked = false discordia.extensions() @@ -265,20 +266,24 @@ client:on('messageCreate', function(message) local cmdName=args[1] table.remove(args,1) local command=commands.command_list[cmdName] - if command~=nil then - if message.guild~=nil then - local s,e=pcall(function() - command.exec({message=message,args=args,mentions=mentions,t={client,discordia,token}}) - end) - if not s then - message:reply('tripped : '..e:split('/')[#e:split('/')]) + if not _G.locked then + if command~=nil then + if message.guild~=nil then + local s,e=pcall(function() + command.exec({message=message,args=args,mentions=mentions,t={client,discordia,token}}) + end) + if not s then + message:reply('tripped : '..e:split('/')[#e:split('/')]) + end + else + message:reply('i will not let you type in dms!!! 😠') end else - message:reply('i will not let you type in dms!!! 😠') + message:reply('command does not exist 👎') end else - message:reply('command does not exist 👎') - end + message:reply('bot is locked, please wait until it is unlocked') + end end end) diff --git a/src/modules/commands/cmds.lua b/src/modules/commands/cmds.lua new file mode 100644 index 0000000..7a0f5e8 --- /dev/null +++ b/src/modules/commands/cmds.lua @@ -0,0 +1,14 @@ +local discordia=require('discordia') +local commands=require('./../commands.lua') +discordia.extensions() +commands:Add('cmds',{'commands','cmd','help'},'Returns a list of all commands',function(t) + local final='```\n' + for i,v in pairs(commands.command_list) do + local name=v.name + local alias=table.concat(v.alias,', ') or 'None' + local desc=v.desc + final=final..'Name: '..name..'\nDescription: '..desc..'\n'..'Aliases: '..alias..'\n\n' + end + final=final..'```' + t.message:reply(final) +end) \ No newline at end of file diff --git a/src/modules/commands/map.lua b/src/modules/commands/map.lua new file mode 100644 index 0000000..08dac28 --- /dev/null +++ b/src/modules/commands/map.lua @@ -0,0 +1,46 @@ +local discordia=require('discordia') +local API=require('./../strafes_net.lua') +local commands=require('./../commands.lua') +discordia.extensions() + +commands:Add('map',{},'get map info', function(t) + local game = API.GAMES[t.args[1]] + local map_name + if not game then + map_name = table.concat(t.args,' ') + else + map_name = table.concat(t.args,' ',2) + end + if not map_name then return t.message:reply('invalid arguments') end + if game then + if API.MAPS[game][map_name] then + local map = API.MAPS[game][map_name] + local formatted_message = '```'.. + 'Map: '..map.DisplayName..' ('..API.GAMES[game]..')\n'.. + 'ID: '..map.ID..'\n'.. + 'Creator: '..map.Creator..'\n'.. + 'PlayCount: '..map.PlayCount..'\n'.. + 'Published: '..os.date('%A, %B %d %Y @ %I:%M (%p)',map.Date).. + '```' + return t.message:reply(formatted_message) + end + else + for _,game in next,API.GAMES do + if type(tonumber(game)) == 'number' then + if API.MAPS[game][map_name] then + local map = API.MAPS[game][map_name] + local formatted_message = '```'.. + 'Map: '..map.DisplayName..' ('..API.GAMES[game]..')\n'.. + 'ID: '..map.ID..'\n'.. + 'Creator: '..map.Creator..'\n'.. + 'PlayCount: '..map.PlayCount..'\n'.. + 'Published: '..os.date('%A, %B %d %Y @ %I:%M (%p)',map.Date).. + '```' + return t.message:reply(formatted_message) + else + return t.message:reply('map not found') + end + end + end + end +end) \ No newline at end of file diff --git a/src/modules/commands/maps_init.lua b/src/modules/commands/maps_init.lua new file mode 100644 index 0000000..1b903ed --- /dev/null +++ b/src/modules/commands/maps_init.lua @@ -0,0 +1,42 @@ +local discordia=require('discordia') +local API=require('./../strafes_net.lua') +discordia.extensions() +API.MAPS={} +for _,game in next,API.GAMES do + if type(tonumber(game)) == 'number' then + local maps = {count=0} + local res,headers = API:GetMaps(game) + local pages = tonumber(headers['Pagination-Count']) + maps.count=maps.count+#res + for _,v in next,res do + maps[v.ID]=v + end + if pages>1 then + for i=2,pages do + res,headers = API:GetMaps(game,i) + maps.count=maps.count+#res + for _,j in next,res do + maps[j.ID]=j + end + end + end + setmetatable(maps,{__index=function(self,i) + if i=='count' then return self.count end + if not tonumber(i) then + for ix,v in next,self do + if type(v)=='table' and v.DisplayName:lower():find(i:lower()) then + return v + end + end + elseif tonumber(i) then + for ix,v in next,self do + if type(v)=='table' and v.ID==i then + return v + end + end + end + end}) + API.MAPS[game]=maps + print('map init done for game:',API.GAMES[game],'count:',API.MAPS[game].count) + end +end \ No newline at end of file diff --git a/src/modules/commands/rank.lua b/src/modules/commands/rank.lua index 95f162d..895bed3 100644 --- a/src/modules/commands/rank.lua +++ b/src/modules/commands/rank.lua @@ -10,6 +10,8 @@ commands:Add('rank',{},'rank