diff --git a/.gitignore b/.gitignore index be023358..d6201c49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ res/ data/ +bot/config.lua +/telegram-bot.sublime-workspace +*.sublime-project .luarocks \ No newline at end of file diff --git a/bot/bot.lua b/bot/bot.lua index 7d48fe7c..b6fd666a 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -205,29 +205,29 @@ function create_config( ) -- A simple config with basic plugins and ourselves as privileged user config = { enabled_plugins = { - "9gag", - "eur", - "echo", - "btc", - "get", - "giphy", - "google", - "gps", - "help", - "id", - "images", - "img_google", - "location", - "media", - "plugins", - "channels", - "set", - "stats", - "time", - "version", - "weather", - "xkcd", - "youtube" }, + "plugins", + "9gag", + "boobs", + "echo", + "giphy", + "google", + "gps", + "help", + "images", + "img_google", + "location", + "media", + "stats", + "weather", + "xkcd", + "vote", + "whoami", + "ball", + "youtube", + "slave", + "slave_agr", + "pornhub", + "hackernews" }, sudo_users = {our_id}, disabled_channels = {} } diff --git a/plugins/ball.lua b/plugins/ball.lua new file mode 100644 index 00000000..c7da5ea0 --- /dev/null +++ b/plugins/ball.lua @@ -0,0 +1,42 @@ + +function run(msg, matches) + + local answers = { + "Ато", + "Предрешено", + "Хрест на пузе, так и будет", + "Определенно да!", + "Считай что это уже случилось ;)", + + "Мне кажется - да", + "Мб", + "У тебя хорошие перспективы", + "Звезды говорят - да", + "Походу да", + + "Будущее туманно...", + "Ахз", + "Лучше не рассказывать...", + "Звезды пока молчат...", + "Сконцентрируйся получше и переспроси", + + "Не в этой жизни", + "Nope", + "Мои соболезнования...", + "Перспективы фиговые", + "Весьма сомнительно :\\" + } + + math.randomseed( os.time() ) + print(math.random(#answers)) + print(math.random(#answers)) + + return string.format(">%s: %s \n%s", get_name(msg), matches[1], answers[math.random(#answers)]) +end + +return { + description = "Гадалко. Спроси у шарика вопрос предпологающий ответ да/нет.", + usage = "!ball <вопрос> - Задай шарику вопрос, предпологающий ответ да/нет", + patterns = {"^!ball (.*)$"}, + run = run +} diff --git a/plugins/curr.lua b/plugins/curr.lua new file mode 100644 index 00000000..93bc0461 --- /dev/null +++ b/plugins/curr.lua @@ -0,0 +1,26 @@ +function run(msg, matches) + + local file = '/home/curr-bot/print' + fh = io.open(file, "r") + + local content = '' + + while true do + local line = fh.read(fh) + if not line then break end + content = content .. line .. "\n" + end + + io.close(fh) + + return content +end + +return { + description = "Prints current UAH currencies.", + usage = "!curr: prints current UAH currencies.", + patterns = { + "^!curr$" + }, + run = run +} diff --git a/plugins/dan.lua b/plugins/dan.lua new file mode 100644 index 00000000..a3a63a58 --- /dev/null +++ b/plugins/dan.lua @@ -0,0 +1,67 @@ +do +local URL = "http://danbooru.donmai.us" +local URL_NEW = "/posts.json" +local URL_POP = "/explore/posts/popular.json" + +local scale_day = "?scale=day" +local scale_week = "?scale=week" +local scale_month = "?scale=month" + +function get_post(url) + local b, c, h = http.request(url) + local posts = json:decode(b) + + -- bad random - bad magic... + math.randomseed( os.time() ) + math.random(#posts) + math.random(#posts) + + return posts[math.random(#posts)] +end + +function run(msg, matches) + + local url = URL + + if matches[1] == "!dan" then + url = url .. URL_NEW + else + url = url .. URL_POP + + if matches[1] == "!dand" then + url = url .. scale_day + elseif matches[1] == "!danw" then + url = url .. scale_week + elseif matches[1] == "!danm" then + url = url .. scale_month + end + end + + local post = get_post(url) + + -- local receiver = get_receiver(msg) + -- local img = URL .. post.large_file_url + -- send_photo_from_url(receiver, img) + + local txt = 'Artist: ' .. post.tag_string_artist .. '\n' + txt = txt .. 'Character: ' .. post.tag_string_character .. '\n' + txt = txt .. '[' .. math.ceil(post.file_size/1000) .. 'kb] ' .. URL .. post.file_url + return txt +end + +return { + description = "Get random fresh or popular image from Danbooru", + usage = { + "!dan - get random fresh image from Danbooru", + "!dand - random daily popular image", + "!danw - random weekly popular image", + "!danm - random monthly popular image"}, + patterns = { + "^!dan$", + "^!dand$", + "^!danw$", + "^!danm$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/echo.lua b/plugins/echo.lua index b42016e3..c9e860dd 100644 --- a/plugins/echo.lua +++ b/plugins/echo.lua @@ -1,20 +1,21 @@ -local function run(msg, matches) - local text = matches[1] - local b = 1 +function run(msg, matches) - while b ~= 0 do - text = text:trim() - text,b = text:gsub('^!+','') - end - return text + local count = tonumber(matches[1]) + local result = "" + + while (count > 0 ) do + result = result .. matches[2] .. "\n" + count = count - 1 + print (result) + end + + return result end return { - description = "Simplest plugin ever!", - usage = "!echo [whatever]: echoes the msg", - patterns = { - "^!echo +(.+)$" - }, - run = run + description = "Simplest plugin ever!", + usage = "!echo [count] [whatever]: echoes the msg N times", + patterns = {"^!echo (%d) (.*)$"}, + run = run } diff --git a/plugins/google.lua b/plugins/google.lua index 6f8e3054..c55d4147 100644 --- a/plugins/google.lua +++ b/plugins/google.lua @@ -20,7 +20,7 @@ end local function stringlinks(results) local stringresults="" for key,val in ipairs(results) do - stringresults=stringresults..val[1].." - "..val[2].."\n" + stringresults=stringresults..val[1].."\n"..val[2].."\n" end return stringresults end diff --git a/plugins/gps.lua b/plugins/gps.lua index 1cc43477..60bd19b4 100644 --- a/plugins/gps.lua +++ b/plugins/gps.lua @@ -5,7 +5,7 @@ function run(msg, matches) local lon = matches[2] local receiver = get_receiver(msg) - local zooms = {16, 18} + local zooms = {15} local urls = {} for i = 1, #zooms do local zoom = zooms[i] @@ -15,12 +15,12 @@ function run(msg, matches) send_photos_from_url(receiver, urls) - return "www.google.es/maps/place/@" .. lat .. "," .. lon + return "www.google.com/maps/place/@" .. lat .. "," .. lon .. ",17z" end return { - description = "generates a map showing the given GPS coordinates", - usage = "!gps latitude,longitude: generates a map showing the given GPS coordinates", + description = "generates a map showing the given GPS coordinates", + usage = "!gps latitude,longitude: generates a map showing the given GPS coordinates (example: !gps 50.449859,30.524089)", patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"}, run = run } diff --git a/plugins/images.lua b/plugins/images.lua index 1b89ee24..983950ba 100644 --- a/plugins/images.lua +++ b/plugins/images.lua @@ -10,9 +10,9 @@ return { description = "When user sends image URL (ends with png, jpg, jpeg) download and send it to origin.", usage = "", patterns = { - "(https?://[%w-_%.%?%.:/%+=&]+%.png)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.jpg)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.jpeg)$", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.png).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.jpg).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.jpeg).*", }, run = run } diff --git a/plugins/imdb.lua b/plugins/imdb.lua index 57691c66..307f8f34 100644 --- a/plugins/imdb.lua +++ b/plugins/imdb.lua @@ -1,6 +1,6 @@ do -local function imdb(movie) +function imdb(msg, movie) local http = require("socket.http") local movie = movie:gsub(' ', '+') local url = "http://www.omdbapi.com/?t=" .. movie @@ -19,15 +19,21 @@ local function imdb(movie) r['Url'] = "http://omdb.com/title/" .. r.imdbID local t = "" for k, v in pairs(r) do - t = t..k..": "..v.. "\n" + if not string.match(k, 'Poster') then + t = t .. k .. ": " .. v .. ".\n" + end end - return t + + local receiver = get_receiver(msg) + send_photo_from_url(receiver, r['Poster']) + + return t:sub(1, -3) end return nil end local function run(msg, matches) - return imdb(matches[1]) + return imdb(msg, matches[1]) end return { diff --git a/plugins/media.lua b/plugins/media.lua index f89f0e7d..28dcbdc0 100644 --- a/plugins/media.lua +++ b/plugins/media.lua @@ -41,17 +41,17 @@ return { description = "When user sends media URL (ends with gif, mp4, pdf, etc.) download and send it to origin.", usage = "", patterns = { - "(https?://[%w-_%.%?%.:/%+=&]+%.(gif))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(mp4))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(pdf))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(ogg))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(zip))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(mp3))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(rar))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(wmv))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(doc))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(avi))$", - "(https?://[%w-_%.%?%.:/%+=&]+%.(webp))$" + ".*(https?://[%w-_%.%?%.:/%+=&]+%.gif).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.mp4).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.pdf).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.ogg).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.zip).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.mp3).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.rar).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.wmv).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.doc).*", + ".*(https?://[%w-_%.%?%.:/%+=&]+%.avi).*" + ".*(https?://[%w-_%.%?%.:/%+=&]+%.(webp)).*" }, run = run } diff --git a/plugins/pornhub.lua b/plugins/pornhub.lua new file mode 100644 index 00000000..08c74c1e --- /dev/null +++ b/plugins/pornhub.lua @@ -0,0 +1,39 @@ +function run(msg, matches) + local results = findPorn(matches[1]) + return results-- build_result(results) +end + +function findPorn(query) + local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:pornhub.com+viewkey+" .. query:gsub(" ", "+") + + -- Do the request + local res, code = https.request(api) + + if code ~=200 then return nil end + local data = json:decode(res) + local results = data.responseData.results + + math.randomseed( os.time() ) + math.random(#results) + math.random(#results) + local index = math.random(#results) + + local result = results[index].titleNoFormatting .. "\n".. results[index].unescapedUrl .."\n" + + return result +end + +function build_result(query) + local stringresults="" + for key,val in ipairs(results) do + stringresults=stringresults..val[1].."\n"..val[2].."\n\n" + end + return stringresults +end + +return { + description = "It's time to fap :)", + usage = "!fap [on something]", + patterns = {"^!fap (.*)$"}, + run = run +} diff --git a/plugins/slave.lua b/plugins/slave.lua new file mode 100644 index 00000000..9a7ab21e --- /dev/null +++ b/plugins/slave.lua @@ -0,0 +1,36 @@ +require("./bot/utils") + +do + +function run(msg, matches) + local url = nil + + if is_sudo(msg) then + return 'Только не по ебалу, хозяин...' + end +end + +return { + description = "", + usage = { + }, + patterns = { + "^Раб.*хуёвый.*", + "^раб.*хуёвый.*", + + "^Раб.*завали.*", + "^раб.*завали.*", + + "^Раб.*ахуел.*", + "^раб.*ахуел.*", + + "^Раб.*мудила.*", + "^раб.*мудила.*", + + "^Раб.*уебок.*", + "^раб.*уебок.*" + }, + run = run +} + +end diff --git a/plugins/slave_agr.lua b/plugins/slave_agr.lua new file mode 100644 index 00000000..d0ade49a --- /dev/null +++ b/plugins/slave_agr.lua @@ -0,0 +1,36 @@ +require("./bot/utils") + +do + +function run(msg, matches) + local url = nil + + if is_sudo(msg) then + return "@vatobot больно пиздит" .. matches[1] .. " дрючком." + end +end + +return { + description = "", + usage = { + }, + patterns = { + "^Раб.*пиздани.*( .*)$", + "^раб.*пиздани.*( .*)$", + + "^Раб.*хуяни.*( .*)$", + "^раб.*хуяни.*( .*)$", + + "^Раб.*побей.*( .*)$", + "^раб.*побей.*( .*)$", + + "^Раб.*карай.*( .*)$", + "^раб.*карай.*( .*)$", + + "^Раб.*накажи.*( .*)$", + "^раб.*накажи.*( .*)$" + }, + run = run +} + +end diff --git a/plugins/weather.lua b/plugins/weather.lua index c0a6fe5f..d42dbc9b 100644 --- a/plugins/weather.lua +++ b/plugins/weather.lua @@ -36,7 +36,7 @@ local function get_weather(location) end local function run(msg, matches) - local city = 'Madrid,ES' + local city = 'Kyiv' if matches[1] ~= '!weather' then city = matches[1] diff --git a/plugins/whoami.lua b/plugins/whoami.lua new file mode 100644 index 00000000..1f043f23 --- /dev/null +++ b/plugins/whoami.lua @@ -0,0 +1,11 @@ +function run(msg, matches) + + return get_receiver(msg) +end + +return { + description = "Returns sender's or chat's id", + usage = "!whoami", + patterns = {"^!whoami$"}, + run = run +}