diff --git a/src/modules/commands/download.lua b/src/modules/commands/download.lua index b9d90c9..227b0f0 100644 --- a/src/modules/commands/download.lua +++ b/src/modules/commands/download.lua @@ -1,7 +1,6 @@ local discordia=require('discordia') local commands=require('./../commands.lua') discordia.extensions() -local io = io function split(s,d) local t,c,i={},'',0 @@ -20,72 +19,46 @@ function split(s,d) end function clearTmp() - for file in io.popen([[dir "./tmp" /b]]):lines() do if file then os.remove('./tmp/'..file) end end + for file in io.popen([[dir "./tmp" /b]]):lines() do + if file then + os.remove('./tmp/'..file) + end + end +end +function isTmpEmpty() + local dir = io.popen([[dir "./tmp" /b]]):read() + return dir==nil, dir, dir~=nil and split(dir,'\n') or {} end -commands:Add('yt',{},"wip", function(t) - clearTmp() - local args = t.args - local message = t.message - if args[1] then - if args[1]:match('?v=([%w-_]+)') or args[1]:match('youtu.be/([%w-_]+)') then - local id=args[1]:match('?v=([%w-_]+)') or args[1]:match('youtu.be/([%w-_]+)') - message:reply('Attempting to download song ID='..id) - local filepath = '' - local name - local s=io.popen('ytdl.exe -x --audio-format mp3 --output "./tmp/%(title)s - %(uploader)s.%(ext)s" '..id) - if s then - repeat - a = split(io.popen([[dir "./tmp" /b]]):read('*all'),'\n') - for _,v in next,a do - if v:sub(#v-3)=='.mp3' then - print(v) - filepath=v - break - end - end - until filepath:sub(#filepath-3)=='.mp3' - if filepath then - message:reply('Found file: '..filepath) - message:reply({file='./tmp/'..filepath}) - os.remove('./tmp/'..filepath) - else - message:reply('Error downloading song (this is not supposed to happen)') - end - else - message:reply('Error downloading song') - end - else - message:reply('Invalid URL') - end - else - message:reply('No URL provided') - end -end) commands:Add('sc',{},"wip", function(t) - clearTmp() local args = t.args local message = t.message if args[1] then if args[1]:match('https://soundcloud.com/[%w-_]+/[%w-_]+') then + clearTmp() local link=args[1]:match('https://soundcloud.com/[%w-_]+/[%w-_]+') message:reply('Attempting to download song from <'..link..'>') - local filepath - local s=io.popen('ytdl.exe -o "./tmp/%(title)s - %(uploader)s.%(ext)s" '..link) - if s then - repeat - local name = io.popen([[dir "./tmp" /b]]):read('*all') - filepath = name:sub(1,name:len()-1) - until filepath:sub(#filepath-3)=='.mp3' - if filepath then - message:reply('Found file: '..filepath) - message:reply({file='./tmp/'..filepath}) - os.remove('./tmp/'..filepath) - else - message:reply('Error downloading song (this is not supposed to happen)') + local filepath = '' + local s=io.popen('ytdl.exe -o "./tmp/%(fulltitle)s.%(ext)s" '..link) + local songName + repeat + local str = s:read() + local tag = str:match('^%[(.+)%]') + if tag=='soundcloud' then + local song = str:match('^%[soundcloud%] (.+):') + if song:match('%d+')~=song then + songName = song:match('.+/(.+)') + end + end + until s:read()==nil + s:close() + if type(songName)=='string' and songName~='' then + message:reply('found song: '..songName) + local empty,file = isTmpEmpty() + if not empty then + message:reply({file='./tmp/'..file}) + os.remove('./tmp/'..file) end - else - message:reply('Error downloading song') end else message:reply('Invalid URL') @@ -93,4 +66,11 @@ commands:Add('sc',{},"wip", function(t) else message:reply('No URL provided') end -end) \ No newline at end of file +end) + +commands:Add('ct',{},'',function() + clearTmp() +end) +-- commands:Add('ft',{},'',function() +-- filterTmp() +-- end) \ No newline at end of file diff --git a/src/modules/commands/maps_init.lua b/src/modules/commands/maps_init.lua index 1b903ed..ebde3dd 100644 --- a/src/modules/commands/maps_init.lua +++ b/src/modules/commands/maps_init.lua @@ -1,42 +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 +-- 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/skillCalc.lua b/src/modules/commands/skillCalc.lua index dcf22ff..97c34df 100644 --- a/src/modules/commands/skillCalc.lua +++ b/src/modules/commands/skillCalc.lua @@ -65,8 +65,6 @@ commands:Add('skill',{},'skill