From 13ddef88fbbdea00c6a2157fa76c2cacffd7ba3e Mon Sep 17 00:00:00 2001 From: Robin Groppe Date: Mon, 26 Oct 2015 12:56:56 +0100 Subject: [PATCH 001/102] Update imdb.lua --- plugins/imdb.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/imdb.lua b/plugins/imdb.lua index 57691c6..37f6256 100644 --- a/plugins/imdb.lua +++ b/plugins/imdb.lua @@ -16,7 +16,7 @@ local function imdb(movie) if r.Error then return r.Error end - r['Url'] = "http://omdb.com/title/" .. r.imdbID + r['Url'] = "http://imdb.com/title/" .. r.imdbID local t = "" for k, v in pairs(r) do t = t..k..": "..v.. "\n" From 26d2e2a8e9cbf19200a2ba348911d0d89434f43a Mon Sep 17 00:00:00 2001 From: Yago Date: Sun, 29 Nov 2015 22:51:52 +0100 Subject: [PATCH 002/102] Update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9948eae..a704d9c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ telegram-bot ============ -[![Join the chat at https://gitter.im/yagop/telegram-bot](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/yagop/telegram-bot?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -[![](https://travis-ci.org/yagop/telegram-bot.svg?branch=master)](https://travis-ci.org/yagop/telegram-bot) -[![Donate button](https://img.shields.io/badge/nepal-donate-yellow.svg)](http://www.nrcs.org/donate-nrcs "Donate to Nepal Red Cross Society") +[![https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw](https://img.shields.io/badge/💬_Telegram-Bot_Dev._Group-blue.svg)](https://telegram.me/node_telegram_bot_api) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬_Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) [![https://gitter.im/yagop/telegram-bot](https://img.shields.io/badge/💬_Gitter-Join_Chat-green.svg)](https://gitter.im/yagop/telegram-bot]) +[![Donate button](https://img.shields.io/badge/Red_Cross-donate-yellow.svg)](https://www.icrc.org/ "Donate to Red Cross Society") A Telegram Bot based on plugins using [tg](https://github.com/vysheng/tg). @@ -362,4 +360,4 @@ Contact me ------------ You can contact me [via Telegram](https://telegram.me/yago_perez) but if you have an issue please [open](https://github.com/yagop/telegram-bot/issues) one. -[Join](https://telegram.me/joinchat/ALJ3iwFAhOCh4WNUHAyzXQ) on the TelegramBot Discussion Group. +[Join](https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw) on the TelegramBot Discussion Group. From a09cce4d8f7c90bdd2a220ed265efe2138b78923 Mon Sep 17 00:00:00 2001 From: Yago Date: Sun, 29 Nov 2015 22:53:05 +0100 Subject: [PATCH 003/102] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a704d9c..78b333a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ telegram-bot ============ -[![https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw](https://img.shields.io/badge/💬_Telegram-Bot_Dev._Group-blue.svg)](https://telegram.me/node_telegram_bot_api) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬_Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) [![https://gitter.im/yagop/telegram-bot](https://img.shields.io/badge/💬_Gitter-Join_Chat-green.svg)](https://gitter.im/yagop/telegram-bot]) +[![https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw](https://img.shields.io/badge/💬_Telegram-Bot_Dev._Group-blue.svg)](https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬_Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) [![https://gitter.im/yagop/telegram-bot](https://img.shields.io/badge/💬_Gitter-Join_Chat-green.svg)](https://gitter.im/yagop/telegram-bot]) [![Donate button](https://img.shields.io/badge/Red_Cross-donate-yellow.svg)](https://www.icrc.org/ "Donate to Red Cross Society") A Telegram Bot based on plugins using [tg](https://github.com/vysheng/tg). From 3845d46172def540664fdc9975126cb418b5766e Mon Sep 17 00:00:00 2001 From: lucasberti Date: Mon, 7 Dec 2015 03:35:47 -0200 Subject: [PATCH 004/102] Fixing torrent_search to work with HTTPS --- plugins/torrent_search.lua | 47 +++++++++++++------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/plugins/torrent_search.lua b/plugins/torrent_search.lua index 74fe194..6038390 100644 --- a/plugins/torrent_search.lua +++ b/plugins/torrent_search.lua @@ -1,36 +1,21 @@ ---[[ NOT USED DUE TO SSL ERROR --- See https://getstrike.net/api/ -local function strike_search(query) - local strike_base = 'http://getstrike.net/api/v2/torrents/' - local url = strike_base..'search/?phrase='..URL.escape(query) - print(url) - local b,c = http.request(url) - print(b,c) - local search = json:decode(b) - vardump(search) - - if c ~= 200 then - return search.message - end - - vardump(search) - local results = search.results - local text = 'Results: '..results - local results = math.min(results, 3) - for i=1,results do - local torrent = search.torrents[i] - text = text..torrent.torrent_title - ..'\n'..'Seeds: '..torrent.seeds - ..' '..'Leeches: '..torrent.seeds - ..'\n'..torrent.magnet_uri..'\n\n' - end - return text -end]]-- +local https = require ('ssl.https') +local ltn12 = require ("ltn12") local function search_kickass(query) - local url = 'http://kat.cr/json.php?q='..URL.escape(query) - local b,c = http.request(url) - local data = json:decode(b) + local url = 'https://kat.cr/json.php?q='..URL.escape(query) + + local resp = {} + + local b,c = https.request + { + url = url, + protocol = "tlsv1", + sink = ltn12.sink.table(resp) + } + + resp = table.concat(resp) + + local data = json:decode(resp) local text = 'Results: '..data.total_results..'\n\n' local results = math.min(#data.list, 5) From c966f32bc94b6335568d8ee31fca9890eaeb815e Mon Sep 17 00:00:00 2001 From: Yago Date: Fri, 1 Jan 2016 22:04:30 +0100 Subject: [PATCH 005/102] Fix Gitter link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78b333a..a311ebd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ telegram-bot ============ -[![https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw](https://img.shields.io/badge/💬_Telegram-Bot_Dev._Group-blue.svg)](https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬_Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) [![https://gitter.im/yagop/telegram-bot](https://img.shields.io/badge/💬_Gitter-Join_Chat-green.svg)](https://gitter.im/yagop/telegram-bot]) +[![https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw](https://img.shields.io/badge/💬_Telegram-Bot_Dev._Group-blue.svg)](https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬_Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) [![https://gitter.im/yagop/telegram-bot](https://img.shields.io/badge/💬_Gitter-Join_Chat-green.svg)](https://gitter.im/yagop/telegram-bot) [![Donate button](https://img.shields.io/badge/Red_Cross-donate-yellow.svg)](https://www.icrc.org/ "Donate to Red Cross Society") A Telegram Bot based on plugins using [tg](https://github.com/vysheng/tg). From af474fe5b693869b8133dbae08ca55e8095d341b Mon Sep 17 00:00:00 2001 From: Yago Date: Tue, 5 Jan 2016 22:03:33 +0100 Subject: [PATCH 006/102] Updated tg --- tg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tg b/tg index 3a898a4..e039351 160000 --- a/tg +++ b/tg @@ -1 +1 @@ -Subproject commit 3a898a42c10ed17ffeecb587ca09cdaa4b39e6b5 +Subproject commit e039351082d5cc791566b0a01a475661b68e13db From 02dc32d3f65be29f810811c1eaff227309c2a07e Mon Sep 17 00:00:00 2001 From: Yago Date: Tue, 5 Jan 2016 22:44:30 +0100 Subject: [PATCH 007/102] Update tg --- tg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tg b/tg index 3a898a4..bde3a39 160000 --- a/tg +++ b/tg @@ -1 +1 @@ -Subproject commit 3a898a42c10ed17ffeecb587ca09cdaa4b39e6b5 +Subproject commit bde3a39be9b6366fe93da623db1ceadd80666bd0 From 0cac958f6e786019d796634c4b539a9dbc03df41 Mon Sep 17 00:00:00 2001 From: Yago Date: Mon, 18 Jan 2016 18:54:32 +0100 Subject: [PATCH 008/102] U --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a311ebd..8071940 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ telegram-bot ============ -[![https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw](https://img.shields.io/badge/💬_Telegram-Bot_Dev._Group-blue.svg)](https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬_Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) [![https://gitter.im/yagop/telegram-bot](https://img.shields.io/badge/💬_Gitter-Join_Chat-green.svg)](https://gitter.im/yagop/telegram-bot) +[![https://yago.me/tg-bot](https://img.shields.io/badge/💬_Telegram-Bot_Dev._Group-blue.svg)](https://yago.me/tg-bot) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬_Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) [![https://gitter.im/yagop/telegram-bot](https://img.shields.io/badge/💬_Gitter-Join_Chat-green.svg)](https://gitter.im/yagop/telegram-bot) [![Donate button](https://img.shields.io/badge/Red_Cross-donate-yellow.svg)](https://www.icrc.org/ "Donate to Red Cross Society") A Telegram Bot based on plugins using [tg](https://github.com/vysheng/tg). From cb70b8b0d1831ef5932134049e40f65135fdbfbd Mon Sep 17 00:00:00 2001 From: Arman Date: Sat, 27 Feb 2016 21:41:14 +0330 Subject: [PATCH 009/102] Update README.md --- README.md | 358 +++--------------------------------------------------- 1 file changed, 14 insertions(+), 344 deletions(-) diff --git a/README.md b/README.md index 8071940..ce28343 100644 --- a/README.md +++ b/README.md @@ -1,324 +1,17 @@ telegram-bot ============ +UpToSky +============ +Bot Based On Yagop +---------------------- +Bot Working IN SUPERGROUPS +---------------------------- +MADE BY @THISISARMAN + @IAMJAVID + @UNFRIENDLY + -[![https://yago.me/tg-bot](https://img.shields.io/badge/💬_Telegram-Bot_Dev._Group-blue.svg)](https://yago.me/tg-bot) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬_Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) [![https://gitter.im/yagop/telegram-bot](https://img.shields.io/badge/💬_Gitter-Join_Chat-green.svg)](https://gitter.im/yagop/telegram-bot) -[![Donate button](https://img.shields.io/badge/Red_Cross-donate-yellow.svg)](https://www.icrc.org/ "Donate to Red Cross Society") - -A Telegram Bot based on plugins using [tg](https://github.com/vysheng/tg). - -Multimedia ----------- -- When user sends image (png, jpg, jpeg) URL download and send it to origin. -- When user sends media (gif, mp4, pdf, etc.) URL download and send it to origin. -- When user sends twitter URL, send text and images to origin. Requires OAuth Key. -- When user sends YouTube URL, send to origin video image. - -![http://i.imgur.com/0FGUvU0.png](http://i.imgur.com/0FGUvU0.png) ![http://i.imgur.com/zW7WWWt.png](http://i.imgur.com/zW7WWWt.png) ![http://i.imgur.com/zW7WWWt.png](http://i.imgur.com/kPK7paz.png) - -Bot Commands ------------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescriptionUsage
9gag.lua9GAG for telegram!9gag: Send random image from 9gag
boobs.luaGets a random boobs or butts pic!boobs: Get a boobs NSFW image. :underage:
!butts: Get a butts NSFW image. :underage:
btc.luaBitcoin global average market value (in EUR or USD)!btc [EUR|USD] [amount]
bugzilla.luaLookup bugzilla status update/bot bugzilla [bug number]
calculator.luaCalculate math expressions with mathjs API!calc [expression]: evaluates the expression and sends the result.
channels.luaPlugin to manage channels. Enable or disable channel.!channel enable: enable current channel
!channel disable: disable current channel
danbooru.luaGets a random fresh or popular image from Danbooru!danbooru - gets a random fresh image from Danbooru :underage:
!danboorud - random daily popular image :underage:
!danbooruw - random weekly popular image :underage:
!danboorum - random monthly popular image :underage:
dogify.luaCreate a doge image with words.!dogify (words/or phrases/separated/by/slashes) - Create a doge image with the words.
download_media.luaWhen bot receives a media msg, download the media.
echo.luaSimplest plugin ever!!echo [whatever]: echoes the msg
eur.luaReal-time EURUSD market price!eur [USD]
expand.luaExpand a shorten URL to the original.!expand [url]
fortunes_uc3m.luaFortunes from Universidad Carlos III!uc3m
get.luaRetrieves variables saved with !set!get (value_name): Returns the value_name value.
giphy.luaGIFs from telegram with Giphy API!gif (term): Search and sends GIF from Giphy. If no param, sends a trending GIF.
!giphy (term): Search and sends GIF from Giphy. If no param, sends a trending GIF.
gnuplot.luaGnuplot plugin!gnuplot [single variable function]: Plot single variable function.
google.luaSearches Google and send results!google [terms]: Searches Google and send results
gps.luagenerates a map showing the given GPS coordinates!gps latitude,longitude: generates a map showing the given GPS coordinates
hackernews.luaShow top 5 hacker news (ycombinator.com)!hackernews
hello.luaSays hello to someonesay hello to [name]
help.luaHelp plugin. Get info from other plugins. !help: Show list of plugins.
!help all: Show all commands for every plugin.
!help [plugin name]: Commands for that plugin.
id.luaKnow your id or the id of a chat members.!id: Return your ID and the chat id if you are in one.
!id(s) chat: Return the IDs of the chat members.
images.luaWhen user sends image URL (ends with png, jpg, jpeg) download and send it to origin.
imdb.luaIMDB plugin for Telegram!imdb [movie]
img_google.luaSearch image with Google API and sends it.!img [term]: Random search an image with Google API.
invite.luaInvite other user to the chat group!invite name [user_name]
!invite id [user_id]
isup.luaCheck if a website or server is up.!isup [host]: Performs a HTTP request or Socket (ip:port) connection
!isup cron [host]: Every 5mins check if host is up. (Requires privileged user)
!isup cron delete [host]: Disable checking that host.
location.luaGets information about a location, maplink and overview!loc (location): Gets information about a location, maplink and overview
magic8ball.luaMagic 8Ball!magic8ball
media.luaWhen user sends media URL (ends with gif, mp4, pdf, etc.) download and send it to origin.
meme.luaGenerate a meme image with up and bottom texts. - !meme search (name): Return the name of the meme that match.
!meme list: Return the link where you can see the memes.
!meme listall: Return the list of all memes. Only admin can call it.
!meme [name] - [text_up] - [text_down]: Generate a meme with the picture that match with that name with the texts provided.
!meme [name] "[text_up]" "[text_down]": Generate a meme with the picture that match with that name with the texts provided.
-
minecraft.luaSearches Minecraft server and sends info!mine [ip]: Searches Minecraft server on specified IP and sends info. Default port: 25565
!mine [ip] [port]: Searches Minecraft server on specified IP and port and sends info.
pili.luaShorten an URL with pili.la service!pili [url]: Short the url
plugins.luaPlugin to manage other plugins. Enable, disable or reload.!plugins: list all plugins.
!plugins enable [plugin]: enable plugin.
!plugins disable [plugin]: disable plugin.
!plugins disable [plugin] chat: disable plugin only this chat.
!plugins reload: reloads all plugins.
qr.luaGiven a text it returns a qr code!qr [text] : returns a black and white qr code
!qr "[background color]" "[data color]" [text] : returns a colored qr code (see !help qr to see how specify colors).
quotes.luaQuote plugin, you can create and retrieves random quotes!addquote [msg]
!quote
rae.luaSpanish dictionary!rae [word]: Search that word in Spanish dictionary.
roll.luaRoll some dice! - !roll d - - | - - d - -
rss.luaManage User/Chat RSS subscriptions.!rss: Get the rss subscriptions.
!rss subscribe (url): Subscribe to that url.
!rss unsubscribe (id): Unsubscribe of that id.
!rss sync: Sync the rss subscriptios now. Only sudo users can use this option.
search_youtube.luaSearch video on YouTube and send it.!youtube [term]: Search for a YouTube video and send it.
set.luaPlugin for saving values. get.lua plugin is necessary to retrieve them.!set [value_name] [data]: Saves the data with the value_name name.
stats.luaPlugin to update user stats.!stats: Returns a list of Username [telegram_id]: msg_num
steam.luaGrabs Steam info for Steam links.
tex.luaConvert LaTeX equation to image!tex [equation]: Convert LaTeX equation to image
time.luaDisplays the local time in an area!time [area]: Displays the local time in that area
translate.luaTranslate some text!translate text. Translate the text to English.
!translate target_lang text.
!translate source,target text
tweet.luaRandom tweet from user!tweet id [id]: Get a random tweet from the user with that ID
!tweet id [id] last: Get a random tweet from the user with that ID
!tweet name [name]: Get a random tweet from the user with that name
!tweet name [name] last: Get a random tweet from the user with that name
twitter.luaWhen user sends twitter URL, send text and images to origin. Requires OAuth Key.
twitter_send.luaSends a tweet!tw [text]: Sends the Tweet with the configured account.
version.luaShows bot version - !version: Shows bot version
vote.luaPlugin for voting in groups.!voting reset: Reset all the votes.
!vote [number]: Cast the vote.
!voting stats: Shows the statistics of voting.
weather.luaweather in that city (Madrid is default)!weather (city)
webshot.luaTake an screenshot of a web.!webshot [url]
wiki.luaSearches Wikipedia and send results!wiki [terms]: Searches wiki and send results
!wiki_set [wiki]: sets the wikimedia site for this chat
!wiki_get: gets the current wikimedia site
xkcd.luaSend comic images from xkcd!xkcd (id): Send an xkcd image and title. If not id, send a random one
youtube.luaSends YouTube info and image.
-[Installation](https://github.com/yagop/telegram-bot/wiki/Installation) ------------ ```bash # Tested on Ubuntu 14.04, for other OSs check out https://github.com/yagop/telegram-bot/wiki/Installation @@ -328,36 +21,13 @@ sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-d ```bash # After those dependencies, lets install the bot cd $HOME -git clone https://github.com/yagop/telegram-bot.git -cd telegram-bot +git clone https://github.com/UPTOSKYPROJECT/UPTOSKY.git +cd UPTOSKY ./launch.sh install ./launch.sh # Will ask you for a phone number & confirmation code. ``` -Enable more [`plugins`](https://github.com/yagop/telegram-bot/tree/master/plugins) -------------- -See the plugins list with `!plugins` command. - -Enable a disabled plugin by `!plugins enable [name]`. - -Disable an enabled plugin by `!plugins disable [name]`. - -Those commands require a privileged user, privileged users are defined inside `data/config.lua` (generated by the bot), stop the bot and edit if necessary. - - -Run it as a daemon ------------- -If your Linux/Unix comes with [upstart](http://upstart.ubuntu.com/) you can run the bot by this way -```bash -$ sed -i "s/yourusername/$(whoami)/g" etc/telegram.conf -$ sed -i "s_telegrambotpath_$(pwd)_g" etc/telegram.conf -$ sudo cp etc/telegram.conf /etc/init/ -$ sudo start telegram # To start it -$ sudo stop telegram # To stop it -``` - Contact me ------------ -You can contact me [via Telegram](https://telegram.me/yago_perez) but if you have an issue please [open](https://github.com/yagop/telegram-bot/issues) one. - -[Join](https://telegram.me/joinchat/ALJ3izwBCNXSswCHOKMwGw) on the TelegramBot Discussion Group. +You can contact ARMAN [via Telegram](https://telegram.me/THISISARMAN) but if you have an issue please +You can contact JAVID [via Telegram](https://telegram.me/IAmJavid) From c5395ded7e3d1478f1cb7cdaf2308911e9eca261 Mon Sep 17 00:00:00 2001 From: Arman Date: Sun, 28 Feb 2016 16:00:37 +0330 Subject: [PATCH 010/102] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce28343..6e99ff9 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,11 @@ Bot Based On Yagop ---------------------- Bot Working IN SUPERGROUPS ---------------------------- -MADE BY @THISISARMAN +MADE BY + @THISISARMAN + @IAMJAVID + @UNFRIENDLY @@ -29,5 +32,8 @@ cd UPTOSKY Contact me ------------ -You can contact ARMAN [via Telegram](https://telegram.me/THISISARMAN) but if you have an issue please +You can contact ARMAN [via Telegram](https://telegram.me/THISISARMAN) + You can contact JAVID [via Telegram](https://telegram.me/IAmJavid) + +You can contact Amir [via Telegram](https://telegram.me/UnFriendly) From f271fe0b1313a90a846f7a766e61a5073bbba803 Mon Sep 17 00:00:00 2001 From: Arman Date: Sun, 28 Feb 2016 16:01:03 +0330 Subject: [PATCH 011/102] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e99ff9..1eaed78 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,9 @@ Bot Based On Yagop Bot Working IN SUPERGROUPS ---------------------------- MADE BY - @THISISARMAN + @THISISARMAN @IAMJAVID - @UNFRIENDLY From 44a2acb943acdaba9d4cabfe86ca2b6269211b3a Mon Sep 17 00:00:00 2001 From: Arman Date: Sun, 28 Feb 2016 16:01:18 +0330 Subject: [PATCH 012/102] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1eaed78..61d0d31 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -telegram-bot ============ UpToSky ============ From 5d41c5354782b76713136c867d2ef986cea0cf02 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 15:57:03 +0330 Subject: [PATCH 013/102] UpToSky V1 --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 056ba89..5448eab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "tg"] path = tg - url = https://github.com/vysheng/tg + url = https://github.com/UPTOSKYPROJECT/tg From 56d1efd05f322f3a326013be28e344134e986c2a Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:01:05 +0330 Subject: [PATCH 014/102] UpToSky V1 --- bot/bot.lua | 64 +++--- bot/utils.lua | 566 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 589 insertions(+), 41 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 7d48fe7..1f07a0b 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -14,6 +14,8 @@ function on_msg_receive (msg) return end + msg = backward_msg_format(msg) + local receiver = get_receiver(msg) -- vardump(msg) @@ -46,7 +48,7 @@ function msg_valid(msg) -- Don't process outgoing messages if msg.out then print('\27[36mNot valid: msg from us\27[39m') - return false + -- return false end -- Before bot was started @@ -72,7 +74,7 @@ function msg_valid(msg) if msg.from.id == our_id then print('\27[36mNot valid: Msg from our id\27[39m') - return false + -- return false end if msg.to.type == 'encr_chat' then @@ -200,41 +202,6 @@ function load_config( ) return config end --- Create a basic config.json file and saves it. -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" }, - sudo_users = {our_id}, - disabled_channels = {} - } - serialize_to_file(config, './data/config.lua') - print ('saved config into ./data/config.lua') -end - function on_our_id (id) our_id = id end @@ -272,6 +239,29 @@ function load_plugins() end end +-- custom add +function load_data(filename) + + local f = io.open(filename) + if not f then + return {} + end + local s = f:read('*all') + f:close() + local data = JSON.decode(s) + + return data + +end + +function save_data(filename, data) + + local s = JSON.encode(data) + local f = io.open(filename, 'w') + f:write(s) + f:close() + +end -- Call and postpone execution for cron plugins function cron_plugins() diff --git a/bot/utils.lua b/bot/utils.lua index 7ac5f8a..ac07213 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -8,6 +8,7 @@ feedparser = require "feedparser" json = (loadfile "./libs/JSON.lua")() mimetype = (loadfile "./libs/mimetype.lua")() redis = (loadfile "./libs/redis.lua")() +JSON = (loadfile "./libs/dkjson.lua")() http.TIMEOUT = 10 @@ -21,6 +22,9 @@ function get_receiver(msg) if msg.to.type == 'encr_chat' then return msg.to.print_name end + if msg.to.type == 'channel' then + return 'channel#id'..msg.to.id + end end function is_chat_msg( msg ) @@ -30,6 +34,12 @@ function is_chat_msg( msg ) return false end +function is_channel_msg( msg ) + if msg.to.type == 'channel' then + return true + end + return false +end function string.random(length) local str = ""; for i = 1, length do @@ -504,19 +514,19 @@ function load_from_file(file, default_data) print ('Created file', file) else print ('Data loaded from file', file) - f:close() + f:close() end return loadfile (file)() end -- See http://stackoverflow.com/a/14899740 function unescape_html(str) - local map = { - ["lt"] = "<", + local map = { + ["lt"] = "<", ["gt"] = ">", ["amp"] = "&", ["quot"] = '"', - ["apos"] = "'" + ["apos"] = "'" } new = string.gsub(str, '(&(#?x?)([%d%a]+);)', function(orig, n, s) var = map[s] or n == "#" and string.char(s) @@ -526,3 +536,551 @@ function unescape_html(str) end) return new end + + +--Check if this chat is realm or not +function is_realm(msg) + local var = false + local realms = 'realms' + local data = load_data(_config.moderation.data) + local chat = msg.to.id + if data[tostring(realms)] then + if data[tostring(realms)][tostring(msg.to.id)] then + var = true + end + return var + end +end +--Check if this chat is a group or not +function is_group(msg) + local var = false + local groups = 'groups' + local data = load_data(_config.moderation.data) + local chat = msg.to.id + if data[tostring(groups)] then + if data[tostring(groups)][tostring(msg.to.id)] then + var = true + end + return var + end +end + + +function savelog(group, logtxt) + +local text = (os.date("[ %c ]=> "..logtxt.."\n \n")) +local file = io.open("./groups/logs/"..group.."log.txt", "a") + +file:write(text) + +file:close() + +end + +function user_print_name(user) + if user.print_name then + return user.print_name + end + local text = '' + if user.first_name then + text = user.last_name..' ' + end + if user.lastname then + text = text..user.last_name + end + return text +end + +--Check if user is the owner of that group or not +function is_owner(msg) + local var = false + local data = load_data(_config.moderation.data) + local user = msg.from.id + + if data[tostring(msg.to.id)] then + if data[tostring(msg.to.id)]['set_owner'] then + if data[tostring(msg.to.id)]['set_owner'] == tostring(user) then + var = true + end + end + end + + if data['admins'] then + if data['admins'][tostring(user)] then + var = true + end + end + for v,user in pairs(_config.sudo_users) do + if user == msg.from.id then + var = true + end + end + return var +end + +function is_owner2(user_id, group_id) + local var = false + local data = load_data(_config.moderation.data) + + if data[tostring(group_id)] then + if data[tostring(group_id)]['set_owner'] then + if data[tostring(group_id)]['set_owner'] == tostring(user_id) then + var = true + end + end + end + + if data['admins'] then + if data['admins'][tostring(user_id)] then + var = true + end + end + for v,user in pairs(_config.sudo_users) do + if user == user_id then + var = true + end + end + return var +end + +--Check if user is admin or not +function is_admin(msg) + local var = false + local data = load_data(_config.moderation.data) + local user = msg.from.id + local admins = 'admins' + if data[tostring(admins)] then + if data[tostring(admins)][tostring(user)] then + var = true + end + end + for v,user in pairs(_config.sudo_users) do + if user == msg.from.id then + var = true + end + end + return var +end +function is_vip(msg) + local var = false + local data = load_data(_config.moderation.data) + local user = msg.from.id + local admins = 'vip' + if data[tostring(admins)] then + if data[tostring(admins)][tostring(user)] then + var = true + end + end + return var +end +local function is_superuser(user_id) + local var = false + local users = user_id + for v,user in pairs(_config.super_users) do + if user == users then + var = true + end + end + return var +end + + +function is_admin2(user_id) + local var = false + local data = load_data(_config.moderation.data) + local user = user_id + local admins = 'admins' + if data[tostring(admins)] then + if data[tostring(admins)][tostring(user)] then + var = true + end + end + for v,user in pairs(_config.sudo_users) do + if user == user_id then + var = true + end + end + return var +end + + + +--Check if user is the mod of that group or not +function is_momod(msg) + local var = false + local data = load_data(_config.moderation.data) + local user = msg.from.id + if data[tostring(msg.to.id)] then + if data[tostring(msg.to.id)]['moderators'] then + if data[tostring(msg.to.id)]['moderators'][tostring(user)] then + var = true + end + end + end + + if data[tostring(msg.to.id)] then + if data[tostring(msg.to.id)]['set_owner'] then + if data[tostring(msg.to.id)]['set_owner'] == tostring(user) then + var = true + end + end + end + + if data['admins'] then + if data['admins'][tostring(user)] then + var = true + end + end + for v,user in pairs(_config.sudo_users) do + if user == msg.from.id then + var = true + end + end + return var +end + +function is_momod2(user_id, group_id) + local var = false + local data = load_data(_config.moderation.data) + local usert = user_id + if data[tostring(group_id)] then + if data[tostring(group_id)]['moderators'] then + if data[tostring(group_id)]['moderators'][tostring(usert)] then + var = true + end + end + end + + if data[tostring(group_id)] then + if data[tostring(group_id)]['set_owner'] then + if data[tostring(group_id)]['set_owner'] == tostring(user_id) then + var = true + end + end + end + + if data['admins'] then + if data['admins'][tostring(user_id)] then + var = true + end + end + for v,user in pairs(_config.sudo_users) do + if user == usert then + var = true + end + end + return var +end + +-- Returns the name of the sender +function kick_user(user_id, chat_id) + if tonumber(user_id) == tonumber(our_id) then -- Ignore bot + return + end + if is_owner2(user_id, chat_id) then -- Ignore admins + return + end + local chat = 'chat#id'..chat_id + local user = 'user#id'..user_id + chat_del_user(chat, user, ok_cb, true) +end + +-- Ban +function ban_user(user_id, chat_id) + if tonumber(user_id) == tonumber(our_id) then -- Ignore bot + return + end + if is_admin2(user_id) then -- Ignore admins + return + end + -- Save to redis + local hash = 'banned:'..chat_id + redis:sadd(hash, user_id) + -- Kick from chat + kick_user(user_id, chat_id) +end +-- Global ban +function banall_user(user_id) + if tonumber(user_id) == tonumber(our_id) then -- Ignore bot + return + end + if is_admin2(user_id) then -- Ignore admins + return + end + -- Save to redis + local hash = 'gbanned' + redis:sadd(hash, user_id) +end +-- Global unban +function unbanall_user(user_id) + --Save on redis + local hash = 'gbanned' + redis:srem(hash, user_id) +end + +-- Check if user_id is banned in chat_id or not +function is_banned(user_id, chat_id) + --Save on redis + local hash = 'banned:'..chat_id + local banned = redis:sismember(hash, user_id) + return banned or false +end +-- Check if user_id is banned in chat_id or not +function is_muted(user_id, chat_id) + --Save on redis + local hash = 'muted:'..chat_id + local muted = redis:sismember(hash, user_id) + return muted or false +end +-- Check if user_id is globally banned or not +function is_gbanned(user_id) + --Save on redis + local hash = 'gbanned' + local banned = redis:sismember(hash, user_id) + return banned or false +end +-- Check if user_id is globally muted or not +function is_gmuted(user_id) + --Save on redis + local hash = 'gmuted' + local muted = redis:sismember(hash, user_id) + return muted or false +end +-- Returns chat_id ban list +function ban_list(chat_id) + local hash = 'banned:'..chat_id + local list = redis:smembers(hash) + local text = "Ban list !\n\n" + for k,v in pairs(list) do + local user_info = redis:hgetall('user:'..v) + if user_info and user_info.print_name then + text = text..k.." - "..string.gsub(user_info.print_name, "_", " ").." ["..v.."]\n" + else + text = text..k.." - "..v.."\n" + end + end + return text +end +-- Returns chat_id mute list +function mute_list(chat_id) + local hash = 'muted:'..chat_id + local list = redis:smembers(hash) + local text = "muted users list !\n\n" + for k,v in pairs(list) do + local user_info = redis:hgetall('user:'..v) + if user_info and user_info.print_name then + text = text..k.." - "..string.gsub(user_info.print_name, "_", " ").." ["..v.."]\n" + else + text = text..k.." - "..v.."\n" + end + end + return text +end + +-- Returns globally ban list +function banall_list() + local hash = 'gbanned' + local list = redis:smembers(hash) + local text = "global bans !\n\n" + for k,v in pairs(list) do + local user_info = redis:hgetall('user:'..v) + if user_info and user_info.print_name then + text = text..k.." - "..string.gsub(user_info.print_name, "_", " ").." ["..v.."]\n" + else + text = text..k.." - "..v.."\n" + end + end + return text +end + +-- /id by reply +function get_message_callback_id(extra, success, result) + if result.to.type == 'chat' then + local chat = 'chat#id'..result.to.id + send_large_msg(chat, result.from.id) + else + return 'Use This in Your Groups' + end +end +-- /id by reply +function get_message_callback_id(extra, success, result) + if result.to.type == 'channel' then + local chat = 'channel#id'..result.to.id + send_large_msg(chat, result.from.id) + else + return 'Use This in Your Groups' + end +end +-- kick by reply for mods and owner +function Kick_by_reply(extra, success, result) + if result.to.type == 'chat' then + local chat = 'chat#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't kick myself" + end + if is_momod2(result.from.id, result.to.id) then -- Ignore mods,owner,admin + return "you can't kick mods,owner and admins" + end + chat_del_user(chat, 'user#id'..result.from.id, ok_cb, false) + else + return 'Use This in Your Groups' + end +end + +-- Kick by reply for admins +function Kick_by_reply_admins(extra, success, result) + if result.to.type == 'chat' then + local chat = 'chat#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't kick myself" + end + if is_admin2(result.from.id) then -- Ignore admins + return + end + chat_del_user(chat, 'user#id'..result.from.id, ok_cb, false) + else + return 'Use This in Your Groups' + end +end + +--Ban by reply for admins +function ban_by_reply(extra, success, result) + if result.to.type == 'chat' then + local chat = 'chat#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't ban myself" + end + if is_momod2(result.from.id, result.to.id) then -- Ignore mods,owner,admin + return "you can't kick mods,owner and admins" + end + ban_user(result.from.id, result.to.id) + send_large_msg(chat, "User "..result.from.id.." Banned") + else + return 'Use This in Your Groups' + end +end + +-- Ban by reply for admins +function ban_by_reply_admins(extra, success, result) + if result.to.type == 'chat' then + local chat = 'chat#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't ban myself" + end + if is_admin2(result.from.id) then -- Ignore admins + return + end + ban_user(result.from.id, result.to.id) + send_large_msg(chat, "User "..result.from.id.." Banned") + else + return 'Use This in Your Groups' + end +end + + + + + + +--mute by reply for admins +function mute_by_reply(extra, success, result) + if result.to.type == 'channel' then + local chat = 'channel#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't mute myself" + end + if is_momod2(result.from.id, result.to.id) then -- Ignore mods,owner,admin + return "you can't mute mods,owner and admins" + end + mute_user(result.from.id, result.to.id) + send_large_msg(chat, "User "..result.from.id.." muted") + else + return 'Use This in Your Groups' + end +end + +-- mute by reply for admins +function mute_by_reply_admins(extra, success, result) + if result.to.type == 'channel' then + local chat = 'channel#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't mute myself" + end + if is_admin2(result.from.id) then -- Ignore admins + return + end + mute_user(result.from.id, result.to.id) + send_large_msg(chat, "User "..result.from.id.." muted") + else + return 'Use This in Your Groups' + end +end + + + + + +-- Unban by reply +function unban_by_reply(extra, success, result) + if result.to.type == 'chat' then + local chat = 'chat#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't unban myself" + end + send_large_msg(chat, "User "..result.from.id.." Unbanned") + -- Save on redis + local hash = 'banned:'..result.to.id + redis:srem(hash, result.from.id) + else + return 'Use This in Your Groups' + end +end +-- unmute by reply +function unmute_by_reply(extra, success, result) + if result.to.type == 'channel' then + local chat = 'channel#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't unmute myself" + end + send_large_msg(chat, "User "..result.from.id.." Unmuted") + -- Save on redis + local hash = 'muted:'..result.to.id + redis:srem(hash, result.from.id) + else + return 'Use This in Your Groups' + end +end +function banall_by_reply(extra, success, result) + if result.to.type == 'chat' then + local chat = 'chat#id'..result.to.id + if tonumber(result.from.id) == tonumber(our_id) then -- Ignore bot + return "I won't banall myself" + end + if is_admin2(result.from.id) then -- Ignore admins + return + end + local name = user_print_name(result.from) + banall_user(result.from.id) + chat_del_user(chat, 'user#id'..result.from.id, ok_cb, false) + send_large_msg(chat, "User "..name.."["..result.from.id.."] hammered") + else + return 'Use This in Your Groups' + end +end +-- Workarrond to format the message as previously was received +function backward_msg_format (msg) + for k,name in ipairs({'from', 'to'}) do + local longid = msg[name].id + msg[name].id = msg[name].peer_id + msg[name].peer_id = longid + msg[name].type = msg[name].peer_type + end + if msg.action and (msg.action.user or msg.action.link_issuer) then + local user = msg.action.user or msg.action.link_issuer + local longid = user.id + user.id = user.peer_id + user.peer_id = longid + user.type = user.peer_type + end + return msg +end From 3ece14291e0d273667abf8fcaa751747554dc258 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:02:30 +0330 Subject: [PATCH 015/102] UpToSky V1 --- data/photos/UPTOSKY V1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 data/photos/UPTOSKY V1 diff --git a/data/photos/UPTOSKY V1 b/data/photos/UPTOSKY V1 new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/data/photos/UPTOSKY V1 @@ -0,0 +1 @@ + From 6b5e2e60eedfdd356ee50f6a0230bf5da18768fa Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:02:43 +0330 Subject: [PATCH 016/102] UpToSky V1 --- data/photos/UPTOSKY V1 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 data/photos/UPTOSKY V1 diff --git a/data/photos/UPTOSKY V1 b/data/photos/UPTOSKY V1 deleted file mode 100644 index 8d1c8b6..0000000 --- a/data/photos/UPTOSKY V1 +++ /dev/null @@ -1 +0,0 @@ - From 12f67b267e9ddb1462e2a9e2101f9bddba84a12b Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:03:47 +0330 Subject: [PATCH 017/102] UpToSky V1 --- data/photos/UPTOSKY V1 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 data/photos/UPTOSKY V1 diff --git a/data/photos/UPTOSKY V1 b/data/photos/UPTOSKY V1 new file mode 100644 index 0000000..806d5be --- /dev/null +++ b/data/photos/UPTOSKY V1 @@ -0,0 +1,2 @@ +UPTOSKY V1 +COPY RIGHT ARMAN JAVID AMIR From b96b80795cd4dcae0915cf4c2dc878ed61d30903 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:04:43 +0330 Subject: [PATCH 018/102] UpToSky V1 --- etc/{telegram.conf => uptosky.conf} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename etc/{telegram.conf => uptosky.conf} (100%) diff --git a/etc/telegram.conf b/etc/uptosky.conf similarity index 100% rename from etc/telegram.conf rename to etc/uptosky.conf From 9397dd3e5341e5f4f6f1295cdb9f4e6921bad156 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:05:26 +0330 Subject: [PATCH 019/102] UpToSky V1 --- libs/dkjson.lua | 809 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 809 insertions(+) create mode 100644 libs/dkjson.lua diff --git a/libs/dkjson.lua b/libs/dkjson.lua new file mode 100644 index 0000000..5687077 --- /dev/null +++ b/libs/dkjson.lua @@ -0,0 +1,809 @@ + -- Module options: + local always_try_using_lpeg = true + local register_global_module_table = false + local global_module_name = 'json' + + --[==[ + +David Kolf's JSON module for Lua 5.1/5.2 +======================================== +*Version 2.4* +In the default configuration this module writes no global values, not even +the module table. Import it using + json = require ("dkjson") +In environments where `require` or a similiar function are not available +and you cannot receive the return value of the module, you can set the +option `register_global_module_table` to `true`. The module table will +then be saved in the global variable with the name given by the option +`global_module_name`. +Exported functions and values: +`json.encode (object [, state])` +-------------------------------- +Create a string representing the object. `Object` can be a table, +a string, a number, a boolean, `nil`, `json.null` or any object with +a function `__tojson` in its metatable. A table can only use strings +and numbers as keys and its values have to be valid objects as +well. It raises an error for any invalid data types or reference +cycles. +`state` is an optional table with the following fields: + - `indent` + When `indent` (a boolean) is set, the created string will contain + newlines and indentations. Otherwise it will be one long line. + - `keyorder` + `keyorder` is an array to specify the ordering of keys in the + encoded output. If an object has keys which are not in this array + they are written after the sorted keys. + - `level` + This is the initial level of indentation used when `indent` is + set. For each level two spaces are added. When absent it is set + to 0. + - `buffer` + `buffer` is an array to store the strings for the result so they + can be concatenated at once. When it isn't given, the encode + function will create it temporary and will return the + concatenated result. + - `bufferlen` + When `bufferlen` is set, it has to be the index of the last + element of `buffer`. + - `tables` + `tables` is a set to detect reference cycles. It is created + temporary when absent. Every table that is currently processed + is used as key, the value is `true`. + +When `state.buffer` was set, the return value will be `true` on +success. Without `state.buffer` the return value will be a string. + +`json.decode (string [, position [, null]])` +-------------------------------------------- + +Decode `string` starting at `position` or at 1 if `position` was +omitted. + +`null` is an optional value to be returned for null values. The +default is `nil`, but you could set it to `json.null` or any other +value. + +The return values are the object or `nil`, the position of the next +character that doesn't belong to the object, and in case of errors +an error message. +Two metatables are created. Every array or object that is decoded gets +a metatable with the `__jsontype` field set to either `array` or +`object`. If you want to provide your own metatables use the syntax + json.decode (string, position, null, objectmeta, arraymeta) +To prevent the assigning of metatables pass `nil`: + json.decode (string, position, null, nil) +`.__jsonorder` +------------------------- +`__jsonorder` can overwrite the `keyorder` for a specific table. +`.__jsontype` +------------------------ +`__jsontype` can be either `"array"` or `"object"`. This value is only +checked for empty tables. (The default for empty tables is `"array"`). +`.__tojson (self, state)` +------------------------------------ +You can provide your own `__tojson` function in a metatable. In this +function you can either add directly to the buffer and return true, +or you can return a string. On errors nil and a message should be +returned. +`json.null` +----------- +You can use this value for setting explicit `null` values. +`json.version` +-------------- +Set to `"dkjson 2.4"`. +`json.quotestring (string)` +--------------------------- +Quote a UTF-8 string and escape critical characters using JSON +escape sequences. This function is only necessary when you build +your own `__tojson` functions. +`json.addnewline (state)` +------------------------- +When `state.indent` is set, add a newline to `state.buffer` and spaces +according to `state.level`. +LPeg support +------------ +When the local configuration variable `always_try_using_lpeg` is set, +this module tries to load LPeg to replace the `decode` function. The +speed increase is significant. You can get the LPeg module at + . +When LPeg couldn't be loaded, the pure Lua functions stay active. + +In case you don't want this module to require LPeg on its own, +disable the option `always_try_using_lpeg` in the options section at +the top of the module. +In this case you can later load LPeg support using +### `json.use_lpeg ()` +Require the LPeg module and replace the functions `quotestring` and +and `decode` with functions that use LPeg patterns. +This function returns the module table, so you can load the module +using: + json = require "dkjson".use_lpeg() +Alternatively you can use `pcall` so the JSON module still works when +LPeg isn't found. + + json = require "dkjson" + pcall (json.use_lpeg) + +### `json.using_lpeg` + +This variable is set to `true` when LPeg was loaded successfully. + +--------------------------------------------------------------------- + +Contact +------- + +You can contact the author by sending an e-mail to 'david' at the +domain 'dkolf.de'. + +--------------------------------------------------------------------- + +*Copyright (C) 2010-2013 David Heiko Kolf* + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + + + \ No newline at end of file From ae8f8abacacc6f3a20105d94fd9672a5a737a7ea Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:06:40 +0330 Subject: [PATCH 020/102] UpToSky V1 --- patches/disable-python-and-libjansson.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/disable-python-and-libjansson.patch b/patches/disable-python-and-libjansson.patch index 1093164..edfdf0d 100644 --- a/patches/disable-python-and-libjansson.patch +++ b/patches/disable-python-and-libjansson.patch @@ -127,4 +127,4 @@ AC_SUBST(EXTRA_LIBS) AC_CONFIG_FILES([Makefile]) AC_OUTPUT -- +-- From c862da7188f60c177cb94a8331c8c5168ecddf5b Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:06:56 +0330 Subject: [PATCH 021/102] UpToSky V1 --- patches/disable-python-and-libjansson.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/disable-python-and-libjansson.patch b/patches/disable-python-and-libjansson.patch index edfdf0d..1093164 100644 --- a/patches/disable-python-and-libjansson.patch +++ b/patches/disable-python-and-libjansson.patch @@ -127,4 +127,4 @@ AC_SUBST(EXTRA_LIBS) AC_CONFIG_FILES([Makefile]) AC_OUTPUT --- +- From 9f6d82d61f09238223afe308f69bad3b477029c3 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:07:37 +0330 Subject: [PATCH 022/102] UpToSky V1 --- .gitignore => .gitignoree | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .gitignore => .gitignoree (52%) diff --git a/.gitignore b/.gitignoree similarity index 52% rename from .gitignore rename to .gitignoree index be02335..fb3a2a0 100644 --- a/.gitignore +++ b/.gitignoree @@ -1,3 +1,3 @@ res/ data/ -.luarocks \ No newline at end of file +.luarocks From aafb9d77b725e59691e0124eceeea66218b7d2d7 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:07:50 +0330 Subject: [PATCH 023/102] UpToSky V1 --- .gitignoree => .gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .gitignoree => .gitignore (100%) diff --git a/.gitignoree b/.gitignore similarity index 100% rename from .gitignoree rename to .gitignore From 96660aedf0564f7600e22ced6e46891e82d93b82 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:08:34 +0330 Subject: [PATCH 024/102] UpToSky V1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61d0d31..b707cbf 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ cd UPTOSKY Contact me ------------ -You can contact ARMAN [via Telegram](https://telegram.me/THISISARMAN) +You can contact ARMAN [via Telegram](https://telegram.me/THiSiSARMAN) You can contact JAVID [via Telegram](https://telegram.me/IAmJavid) From aa19c9f51a2bdef51809bab6f183d8210cb7f902 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:09:21 +0330 Subject: [PATCH 025/102] UpToSky V1 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5704265..2e5d03e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: erlang before_install: - - sudo apt-get update -qq + - sudo apt-get update qq - sudo apt-get install -qq libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev make unzip git libjansson-dev python2.7-dev - ./launch.sh install From e051d9ff55eccfac83609265980f30d7921211b6 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:09:34 +0330 Subject: [PATCH 026/102] UpToSky V1 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2e5d03e..5704265 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: erlang before_install: - - sudo apt-get update qq + - sudo apt-get update -qq - sudo apt-get install -qq libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev make unzip git libjansson-dev python2.7-dev - ./launch.sh install From 184d06ca65e45f7ff120dd8a34c82a28354531cd Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:10:03 +0330 Subject: [PATCH 027/102] UpToSky V1 From 3c5fe3925fc6f980debbdce6528d82af9e500328 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:10:27 +0330 Subject: [PATCH 028/102] UpToSky V1 From c0aa767a13b001e019185840f847f05a6ccda8d9 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:11:39 +0330 Subject: [PATCH 029/102] UpToSky V1 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 27b4e5e..a4de330 100644 --- a/LICENSE +++ b/LICENSE @@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} - Copyright (C) 2015 Yago Pérez + Copyright (C) 2015 Yago Pérez This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by From 855e041096d8313f91f58faec2e12e012ed7f5c8 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:12:34 +0330 Subject: [PATCH 030/102] UpToSky V1 --- launch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch.sh b/launch.sh index 8b98ff6..1b66e72 100755 --- a/launch.sh +++ b/launch.sh @@ -112,4 +112,4 @@ else fi ./tg/bin/telegram-cli -k ./tg/tg-server.pub -s ./bot/bot.lua -l 1 -E $@ -fi +fii From 3ccc1d1554e2d9565889f5c8227c9529d1c4afc1 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:12:49 +0330 Subject: [PATCH 031/102] UpToSky V1 --- launch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch.sh b/launch.sh index 1b66e72..8b98ff6 100755 --- a/launch.sh +++ b/launch.sh @@ -112,4 +112,4 @@ else fi ./tg/bin/telegram-cli -k ./tg/tg-server.pub -s ./bot/bot.lua -l 1 -E $@ -fii +fi From 225009c8ecf603a0eb32a5f2b0130585541bcc14 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:13:07 +0330 Subject: [PATCH 032/102] Delete youtube.lua --- plugins/youtube.lua | 58 --------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 plugins/youtube.lua diff --git a/plugins/youtube.lua b/plugins/youtube.lua deleted file mode 100644 index 9a94734..0000000 --- a/plugins/youtube.lua +++ /dev/null @@ -1,58 +0,0 @@ -do - local google_config = load_from_file('data/google.lua') - - local function httpsRequest(url) - print(url) - local res,code = https.request(url) - if code ~= 200 then return nil end - return json:decode(res) - end - - function get_yt_data (yt_code) - local url = 'https://www.googleapis.com/youtube/v3/videos?' - url = url .. 'id=' .. URL.escape(yt_code) .. '&part=snippet' - if google_config.api_keys then - local i = math.random(#google_config.api_keys) - local api_key = google_config.api_keys[i] - if api_key then - url = url.."&key="..api_key - end - end - return httpsRequest(url) - end - - function send_youtube_data(data, receiver) - local title = data.title - local description = data.description - local uploader = data.channelTitle - local text = title..' ('..uploader..')\n'..description - local image_url = data.thumbnails.high.url or data.thumbnails.default.url - local cb_extra = { - receiver = receiver, - url = image_url - } - send_msg(receiver, text, send_photo_from_url_callback, cb_extra) - end - - function run(msg, matches) - local yt_code = matches[1] - local data = get_yt_data(yt_code) - if data == nil or #data.items == 0 then - return "I didn't find info about that video." - end - local senddata = data.items[1].snippet - local receiver = get_receiver(msg) - send_youtube_data(senddata, receiver) - end - - return { - description = "Sends YouTube info and image.", - usage = "", - patterns = { - "youtu.be/([_A-Za-z0-9-]+)", - "youtube.com/watch%?v=([_A-Za-z0-9-]+)", - }, - run = run - } - -end From 6e5e5ccfa3a7756f1afbbfa1b0061f532bde96b0 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:14:08 +0330 Subject: [PATCH 033/102] Delete wiki.lua --- plugins/wiki.lua | 177 ----------------------------------------------- 1 file changed, 177 deletions(-) delete mode 100644 plugins/wiki.lua diff --git a/plugins/wiki.lua b/plugins/wiki.lua deleted file mode 100644 index 99b117e..0000000 --- a/plugins/wiki.lua +++ /dev/null @@ -1,177 +0,0 @@ --- http://git.io/vUA4M -local socket = require "socket" -local JSON = require "cjson" - -local wikiusage = { - "!wiki [text]: Read extract from default Wikipedia (EN)", - "!wiki(lang) [text]: Read extract from 'lang' Wikipedia. Example: !wikies hola", - "!wiki search [text]: Search articles on default Wikipedia (EN)", - "!wiki(lang) search [text]: Search articles on 'lang' Wikipedia. Example: !wikies search hola", -} - -local Wikipedia = { - -- http://meta.wikimedia.org/wiki/List_of_Wikipedias - wiki_server = "https://%s.wikipedia.org", - wiki_path = "/w/api.php", - wiki_load_params = { - action = "query", - prop = "extracts", - format = "json", - exchars = 300, - exsectionformat = "plain", - explaintext = "", - redirects = "" - }, - wiki_search_params = { - action = "query", - list = "search", - srlimit = 20, - format = "json", - }, - default_lang = "en", -} - -function Wikipedia:getWikiServer(lang) - return string.format(self.wiki_server, lang or self.default_lang) -end - ---[[ --- return decoded JSON table from Wikipedia ---]] -function Wikipedia:loadPage(text, lang, intro, plain, is_search) - local request, sink = {}, {} - local query = "" - local parsed - - if is_search then - for k,v in pairs(self.wiki_search_params) do - query = query .. k .. '=' .. v .. '&' - end - parsed = URL.parse(self:getWikiServer(lang)) - parsed.path = self.wiki_path - parsed.query = query .. "srsearch=" .. URL.escape(text) - else - self.wiki_load_params.explaintext = plain and "" or nil - for k,v in pairs(self.wiki_load_params) do - query = query .. k .. '=' .. v .. '&' - end - parsed = URL.parse(self:getWikiServer(lang)) - parsed.path = self.wiki_path - parsed.query = query .. "titles=" .. URL.escape(text) - end - - -- HTTP request - request['url'] = URL.build(parsed) - print(request['url']) - request['method'] = 'GET' - request['sink'] = ltn12.sink.table(sink) - - local httpRequest = parsed.scheme == 'http' and http.request or https.request - local code, headers, status = socket.skip(1, httpRequest(request)) - - if not headers or not sink then - return nil - end - - local content = table.concat(sink) - if content ~= "" then - local ok, result = pcall(JSON.decode, content) - if ok and result then - return result - else - return nil - end - else - return nil - end -end - --- extract intro passage in wiki page -function Wikipedia:wikintro(text, lang) - local result = self:loadPage(text, lang, true, true) - - if result and result.query then - - local query = result.query - if query and query.normalized then - text = query.normalized[1].to or text - end - - local page = query.pages[next(query.pages)] - - if page and page.extract then - return text..": "..page.extract - else - local text = "Extract not found for "..text - text = text..'\n'..table.concat(wikiusage, '\n') - return text - end - else - return "Sorry an error happened" - end -end - --- search for term in wiki -function Wikipedia:wikisearch(text, lang) - local result = self:loadPage(text, lang, true, true, true) - - if result and result.query then - local titles = "" - for i,item in pairs(result.query.search) do - titles = titles .. "\n" .. item["title"] - end - titles = titles ~= "" and titles or "No results found" - return titles - else - return "Sorry, an error occurred" - end - -end - -local function run(msg, matches) - -- TODO: Remember language (i18 on future version) - -- TODO: Support for non Wikipedias but Mediawikis - local search, term, lang - if matches[1] == "search" then - search = true - term = matches[2] - lang = nil - elseif matches[2] == "search" then - search = true - term = matches[3] - lang = matches[1] - else - term = matches[2] - lang = matches[1] - end - if not term then - term = lang - lang = nil - end - if term == "" then - local text = "Usage:\n" - text = text..table.concat(wikiusage, '\n') - return text - end - - local result - if search then - result = Wikipedia:wikisearch(term, lang) - else - -- TODO: Show the link - result = Wikipedia:wikintro(term, lang) - end - return result -end - -return { - description = "Searches Wikipedia and send results", - usage = wikiusage, - patterns = { - "^![Ww]iki(%w+) (search) (.+)$", - "^![Ww]iki (search) ?(.*)$", - "^![Ww]iki(%w+) (.+)$", - "^![Ww]iki ?(.*)$" - }, - run = run -} From 5d09b5ebede08deabf6081c870e3b2256057cd25 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:14:12 +0330 Subject: [PATCH 034/102] Delete xkcd.lua --- plugins/xkcd.lua | 58 ------------------------------------------------ 1 file changed, 58 deletions(-) delete mode 100644 plugins/xkcd.lua diff --git a/plugins/xkcd.lua b/plugins/xkcd.lua deleted file mode 100644 index 37b23a3..0000000 --- a/plugins/xkcd.lua +++ /dev/null @@ -1,58 +0,0 @@ -do - -function get_last_id() - local res,code = https.request("http://xkcd.com/info.0.json") - if code ~= 200 then return "HTTP ERROR" end - local data = json:decode(res) - return data.num -end - -function get_xkcd(id) - local res,code = http.request("http://xkcd.com/"..id.."/info.0.json") - if code ~= 200 then return "HTTP ERROR" end - local data = json:decode(res) - local link_image = data.img - if link_image:sub(0,2) == '//' then - link_image = msg.text:sub(3,-1) - end - return link_image, data.title, data.alt -end - - -function get_xkcd_random() - local last = get_last_id() - local i = math.random(1, last) - return get_xkcd(i) -end - -function send_title(cb_extra, success, result) - if success then - local message = cb_extra[2] .. "\n" .. cb_extra[3] - send_msg(cb_extra[1], message, ok_cb, false) - end -end - -function run(msg, matches) - local receiver = get_receiver(msg) - if matches[1] == "!xkcd" then - url, title, alt = get_xkcd_random() - else - url, title, alt = get_xkcd(matches[1]) - end - file_path = download_to_file(url) - send_photo(receiver, file_path, send_title, {receiver, title, alt}) - return false -end - -return { - description = "Send comic images from xkcd", - usage = {"!xkcd (id): Send an xkcd image and title. If not id, send a random one"}, - patterns = { - "^!xkcd$", - "^!xkcd (%d+)", - "xkcd.com/(%d+)" - }, - run = run -} - -end From 8a1959a8eebc5381ec7feceee070e6fd8c8161c8 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:14:17 +0330 Subject: [PATCH 035/102] Delete yoda.lua --- plugins/yoda.lua | 50 ------------------------------------------------ 1 file changed, 50 deletions(-) delete mode 100644 plugins/yoda.lua diff --git a/plugins/yoda.lua b/plugins/yoda.lua deleted file mode 100644 index 7674aa1..0000000 --- a/plugins/yoda.lua +++ /dev/null @@ -1,50 +0,0 @@ -local ltn12 = require "ltn12" -local https = require "ssl.https" - --- Edit data/mashape.lua with your Mashape API key --- http://docs.mashape.com/api-keys -local mashape = load_from_file('data/mashape.lua', { - api_key = '' - }) - -local function request(text) - local api = "https://yoda.p.mashape.com/yoda?" - text = string.gsub(text, " ", "+") - local parameters = "sentence="..(text or "") - local url = api..parameters - - local api_key = mashape.api_key - if api_key:isempty() then - return 'Configure your Mashape API Key' - end - - local headers = { - ["X-Mashape-Key"] = api_key, - ["Accept"] = "text/plain" - } - - local respbody = {} - local body, code = https.request{ - url = url, - method = "GET", - headers = headers, - sink = ltn12.sink.table(respbody), - protocol = "tlsv1" - } - if code ~= 200 then return code end - local body = table.concat(respbody) - return body -end - -local function run(msg, matches) - return request(matches[1]) -end - -return { - description = "Listen to Yoda and learn from his words!", - usage = "!yoda You will learn how to speak like me someday.", - patterns = { - "^![y|Y]oda (.*)$" - }, - run = run -} From 78e4ff7980394ef56e4662a76dfaa06d9c7da314 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:14:54 +0330 Subject: [PATCH 036/102] Delete anti-bot.lua --- plugins/anti-bot.lua | 113 ------------------------------------------- 1 file changed, 113 deletions(-) delete mode 100644 plugins/anti-bot.lua diff --git a/plugins/anti-bot.lua b/plugins/anti-bot.lua deleted file mode 100644 index 9edeaf5..0000000 --- a/plugins/anti-bot.lua +++ /dev/null @@ -1,113 +0,0 @@ - -local function isBotAllowed (userId, chatId) - local hash = 'anti-bot:allowed:'..chatId..':'..userId - local banned = redis:get(hash) - return banned -end - -local function allowBot (userId, chatId) - local hash = 'anti-bot:allowed:'..chatId..':'..userId - redis:set(hash, true) -end - -local function disallowBot (userId, chatId) - local hash = 'anti-bot:allowed:'..chatId..':'..userId - redis:del(hash) -end - --- Is anti-bot enabled on chat -local function isAntiBotEnabled (chatId) - local hash = 'anti-bot:enabled:'..chatId - local enabled = redis:get(hash) - return enabled -end - -local function enableAntiBot (chatId) - local hash = 'anti-bot:enabled:'..chatId - redis:set(hash, true) -end - -local function disableAntiBot (chatId) - local hash = 'anti-bot:enabled:'..chatId - redis:del(hash) -end - -local function isABot (user) - -- Flag its a bot 0001000000000000 - local binFlagIsBot = 4096 - local result = bit32.band(user.flags, binFlagIsBot) - return result == binFlagIsBot -end - -local function kickUser(userId, chatId) - local chat = 'chat#id'..chatId - local user = 'user#id'..userId - chat_del_user(chat, user, function (data, success, result) - if success ~= 1 then - print('I can\'t kick '..data.user..' but should be kicked') - end - end, {chat=chat, user=user}) -end - -local function run (msg, matches) - -- We wont return text if is a service msg - if matches[1] ~= 'chat_add_user' and matches[1] ~= 'chat_add_user_link' then - if msg.to.type ~= 'chat' then - return 'Anti-flood works only on channels' - end - end - - local chatId = msg.to.id - if matches[1] == 'enable' then - enableAntiBot(chatId) - return 'Anti-bot enabled on this chat' - end - if matches[1] == 'disable' then - disableAntiBot(chatId) - return 'Anti-bot disabled on this chat' - end - if matches[1] == 'allow' then - local userId = matches[2] - allowBot(userId, chatId) - return 'Bot '..userId..' allowed' - end - if matches[1] == 'disallow' then - local userId = matches[2] - disallowBot(userId, chatId) - return 'Bot '..userId..' disallowed' - end - if matches[1] == 'chat_add_user' or matches[1] == 'chat_add_user_link' then - local user = msg.action.user or msg.from - if isABot(user) then - print('It\'s a bot!') - if isAntiBotEnabled(chatId) then - print('Anti bot is enabled') - local userId = user.id - if not isBotAllowed(userId, chatId) then - kickUser(userId, chatId) - else - print('This bot is allowed') - end - end - end - end -end - -return { - description = 'When bot enters group kick it.', - usage = { - '!antibot enable: Enable Anti-bot on current chat', - '!antibot disable: Disable Anti-bot on current chat', - '!antibot allow : Allow on this chat', - '!antibot disallow : Disallow on this chat' - }, - patterns = { - '^!antibot (allow) (%d+)$', - '^!antibot (disallow) (%d+)$', - '^!antibot (enable)$', - '^!antibot (disable)$', - '^!!tgservice (chat_add_user)$', - '^!!tgservice (chat_add_user_link)$' - }, - run = run -} From 83135cc31eb7ecae08f8f9407041a5844b87785e Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:14:57 +0330 Subject: [PATCH 037/102] Delete lyrics.lua --- plugins/lyrics.lua | 97 ---------------------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 plugins/lyrics.lua diff --git a/plugins/lyrics.lua b/plugins/lyrics.lua deleted file mode 100644 index 3661248..0000000 --- a/plugins/lyrics.lua +++ /dev/null @@ -1,97 +0,0 @@ -do - -local BASE_LNM_URL = 'http://api.lyricsnmusic.com/songs' -local LNM_APIKEY = '1f5ea5cf652d9b2ba5a5118a11dba5' - -local BASE_LYRICS_URL = 'http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect' - -local function getInfo(query) - print('Getting info of ' .. query) - - local url = BASE_LNM_URL..'?api_key='..LNM_APIKEY - ..'&q='..URL.escape(query) - - local b, c = http.request(url) - if c ~= 200 then - return nil - end - - local result = json:decode(b) - local artist = result[1].artist.name - local track = result[1].title - return artist, track -end - -local function getLyrics(query) - - local artist, track = getInfo(query) - if artist and track then - local url = BASE_LYRICS_URL..'?artist='..URL.escape(artist) - ..'&song='..URL.escape(track) - - local b, c = http.request(url) - if c ~= 200 then - return nil - end - - local xml = require("xml") - local result = xml.load(b) - - if not result then - return nil - end - - if xml.find(result, 'LyricSong') then - track = xml.find(result, 'LyricSong')[1] - end - - if xml.find(result, 'LyricArtist') then - artist = xml.find(result, 'LyricArtist')[1] - end - - local lyric - if xml.find(result, 'Lyric') then - lyric = xml.find(result, 'Lyric')[1] - else - lyric = nil - end - - local cover - if xml.find(result, 'LyricCovertArtUrl') then - cover = xml.find(result, 'LyricCovertArtUrl')[1] - else - cover = nil - end - - return artist, track, lyric, cover - - else - return nil - end - -end - - -local function run(msg, matches) - local artist, track, lyric, cover = getLyrics(matches[1]) - if track and artist and lyric then - if cover then - local receiver = get_receiver(msg) - send_photo_from_url(receiver, cover) - end - return '🎵 ' .. artist .. ' - ' .. track .. ' 🎵\n----------\n' .. lyric - else - return 'Oops! Lyrics not found or something like that! :/' - end -end - -return { - description = 'Getting lyrics of a song', - usage = '!lyrics [track or artist - track]: Search and get lyrics of the song', - patterns = { - '^!lyrics? (.*)$' - }, - run = run -} - -end From 7a43581fd5bd78e0b21a305733a66a26dd3a84c5 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:15:00 +0330 Subject: [PATCH 038/102] Delete webshot.lua --- plugins/webshot.lua | 56 --------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 plugins/webshot.lua diff --git a/plugins/webshot.lua b/plugins/webshot.lua deleted file mode 100644 index 3726802..0000000 --- a/plugins/webshot.lua +++ /dev/null @@ -1,56 +0,0 @@ -local helpers = require "OAuth.helpers" - -local base = 'https://screenshotmachine.com/' -local url = base .. 'processor.php' - -local function get_webshot_url(param) - local response_body = {} - local request_constructor = { - url = url, - method = "GET", - sink = ltn12.sink.table(response_body), - headers = { - referer = base, - dnt = "1", - origin = base, - ["User-Agent"] = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36" - }, - redirect = false - } - - local arguments = { - urlparam = param, - size = "FULL" - } - - request_constructor.url = url .. "?" .. helpers.url_encode_arguments(arguments) - - local ok, response_code, response_headers, response_status_line = https.request(request_constructor) - if not ok or response_code ~= 200 then - return nil - end - - local response = table.concat(response_body) - return string.match(response, "href='(.-)'") -end - -local function run(msg, matches) - local find = get_webshot_url(matches[1]) - if find then - local imgurl = base .. find - local receiver = get_receiver(msg) - send_photo_from_url(receiver, imgurl) - end -end - - -return { - description = "Send an screenshot of a website.", - usage = { - "!webshot [url]: Take an screenshot of the web and send it back to you." - }, - patterns = { - "^!webshot (https?://[%w-_%.%?%.:/%+=&]+)$", - }, - run = run -} From fb567164af612ef0bd9f90d87befe2ffd581ec20 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 16:15:04 +0330 Subject: [PATCH 039/102] Delete 9gag.lua --- plugins/9gag.lua | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 plugins/9gag.lua diff --git a/plugins/9gag.lua b/plugins/9gag.lua deleted file mode 100644 index 8813fe1..0000000 --- a/plugins/9gag.lua +++ /dev/null @@ -1,38 +0,0 @@ -do - -local function get_9GAG() - local url = "http://api-9gag.herokuapp.com/" - local b,c = http.request(url) - if c ~= 200 then return nil end - local gag = json:decode(b) - -- random max json table size - local i = math.random(#gag) - local link_image = gag[i].src - local title = gag[i].title - if link_image:sub(0,2) == '//' then - link_image = msg.text:sub(3,-1) - end - return link_image, title -end - -local function send_title(cb_extra, success, result) - if success then - send_msg(cb_extra[1], cb_extra[2], ok_cb, false) - end -end - -local function run(msg, matches) - local receiver = get_receiver(msg) - local url, title = get_9GAG() - send_photo_from_url(receiver, url, send_title, {receiver, title}) - return false -end - -return { - description = "9GAG for Telegram", - usage = "!9gag: Send random image from 9gag", - patterns = {"^!9gag$"}, - run = run -} - -end \ No newline at end of file From 100a1ac6c883de53372d354e9cb47377f60504b6 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:16:45 +0330 Subject: [PATCH 040/102] Delete bugzilla.lua --- plugins/bugzilla.lua | 105 ------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 plugins/bugzilla.lua diff --git a/plugins/bugzilla.lua b/plugins/bugzilla.lua deleted file mode 100644 index ffeeadb..0000000 --- a/plugins/bugzilla.lua +++ /dev/null @@ -1,105 +0,0 @@ -do - -local BASE_URL = "https://bugzilla.mozilla.org/rest/" - -local function bugzilla_login() - local url = BASE_URL.."login?login=" .. _config.bugzilla.username .. "&password=" .. _config.bugzilla.password - print("accessing " .. url) - local res,code = https.request( url ) - local data = json:decode(res) - return data -end - -local function bugzilla_check(id) - -- data = bugzilla_login() - local url = BASE_URL.."bug/" .. id .. "?api_key=" .. _config.bugzilla.apikey - -- print(url) - local res,code = https.request( url ) - local data = json:decode(res) - return data -end - -local function bugzilla_listopened(email) - local url = BASE_URL.."bug?include_fields=id,summary,status,whiteboard,resolution&email1=" .. email .. "&email2=" .. email .. "&emailassigned_to2=1&emailreporter1=1&emailtype1=substring&emailtype2=substring&f1=bug_status&f2=bug_status&n1=1&n2=1&o1=equals&o2=equals&resolution=---&v1=closed&v2=resolved&api_key=" .. _config.bugzilla.apikey - local res,code = https.request( url ) - print(res) - local data = json:decode(res) - return data -end - -local function run(msg, matches) - - local response = "" - - if matches[1] == "status" then - local data = bugzilla_check(matches[2]) - vardump(data) - if data.error == true then - return "Sorry, API failed with message: " .. data.message - else - response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator - response = response .. "\n Last update: "..data.bugs[1].last_change_time - response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution - response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard - response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1] - print(response) - end - elseif matches[1] == "list" then - local data = bugzilla_listopened(matches[2]) - - vardump(data) - if data.error == true then - return "Sorry, API failed with message: " .. data.message - else - - -- response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator - -- response = response .. "\n Last update: "..data.bugs[1].last_change_time - -- response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution - -- response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard - -- response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1] - local total = table.map_length(data.bugs) - - print("total bugs: " .. total) - local response = "There are " .. total .. " number of bug(s) assigned/reported by " .. matches[2] - - if total > 0 then - response = response .. ": " - - for tableKey, bug in pairs(data.bugs) do - response = response .. "\n #" .. bug.id - response = response .. "\n Status: " .. bug.status .. " " .. bug.resolution - response = response .. "\n Whiteboard: " .. bug.whiteboard - response = response .. "\n Summary: " .. bug.summary - end - end - end - - end - return response -end - --- (table) --- [bugs] = (table) --- [1] = (table) --- [status] = (string) ASSIGNED --- [id] = (number) 927704 --- [whiteboard] = (string) [approved][full processed] --- [summary] = (string) Budget Request - Arief Bayu Purwanto - https://reps.mozilla.org/e/mozilla-summit-2013/ --- [2] = (table) --- [status] = (string) ASSIGNED --- [id] = (number) 1049337 --- [whiteboard] = (string) [approved][full processed][waiting receipts][waiting report and photos] --- [summary] = (string) Budget Request - Arief Bayu Purwanto - https://reps.mozilla.org/e/workshop-firefox-os-pada-workshop-media-sosial-untuk-perubahan-1/ --- total bugs: 2 - -return { - description = "Lookup bugzilla status update", - usage = "/bot bugzilla [bug number]", - patterns = { - "^/bugzilla (status) (.*)$", - "^/bugzilla (list) (.*)$" - }, - run = run -} - -end \ No newline at end of file From 501d713e7dd93829841cb9adf6f5b9cdf67b7ea2 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:16:48 +0330 Subject: [PATCH 041/102] Delete anti-flood.lua --- plugins/anti-flood.lua | 87 ------------------------------------------ 1 file changed, 87 deletions(-) delete mode 100644 plugins/anti-flood.lua diff --git a/plugins/anti-flood.lua b/plugins/anti-flood.lua deleted file mode 100644 index 0cb74e6..0000000 --- a/plugins/anti-flood.lua +++ /dev/null @@ -1,87 +0,0 @@ -local NUM_MSG_MAX = 5 -- Max number of messages per TIME_CHECK seconds -local TIME_CHECK = 5 - -local function kick_user(user_id, chat_id) - local chat = 'chat#id'..chat_id - local user = 'user#id'..user_id - chat_del_user(chat, user, function (data, success, result) - if success ~= 1 then - local text = 'I can\'t kick '..data.user..' but should be kicked' - send_msg(data.chat, '', ok_cb, nil) - end - end, {chat=chat, user=user}) -end - -local function run (msg, matches) - if msg.to.type ~= 'chat' then - return 'Anti-flood works only on channels' - else - local chat = msg.to.id - local hash = 'anti-flood:enabled:'..chat - if matches[1] == 'enable' then - redis:set(hash, true) - return 'Anti-flood enabled on chat' - end - if matches[1] == 'disable' then - redis:del(hash) - return 'Anti-flood disabled on chat' - end - end -end - -local function pre_process (msg) - -- Ignore service msg - if msg.service then - print('Service message') - return msg - end - - local hash_enable = 'anti-flood:enabled:'..msg.to.id - local enabled = redis:get(hash_enable) - - if enabled then - print('anti-flood enabled') - -- Check flood - if msg.from.type == 'user' then - -- Increase the number of messages from the user on the chat - local hash = 'anti-flood:'..msg.from.id..':'..msg.to.id..':msg-num' - local msgs = tonumber(redis:get(hash) or 0) - if msgs > NUM_MSG_MAX then - local receiver = get_receiver(msg) - local user = msg.from.id - local text = 'User '..user..' is flooding' - local chat = msg.to.id - - send_msg(receiver, text, ok_cb, nil) - if msg.to.type ~= 'chat' then - print("Flood in not a chat group!") - elseif user == tostring(our_id) then - print('I won\'t kick myself') - elseif is_sudo(msg) then - print('I won\'t kick an admin!') - else - -- Ban user - -- TODO: Check on this plugin bans - local bhash = 'banned:'..msg.to.id..':'..msg.from.id - redis:set(bhash, true) - kick_user(user, chat) - end - msg = nil - end - redis:setex(hash, TIME_CHECK, msgs+1) - end - end - return msg -end - -return { - description = 'Plugin to kick flooders from group.', - usage = {}, - patterns = { - '^!antiflood (enable)$', - '^!antiflood (disable)$' - }, - run = run, - privileged = true, - pre_process = pre_process -} From e033a870d4de4de0332bf4efe89a61dbb06f1b2d Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:16:51 +0330 Subject: [PATCH 042/102] Delete banhammer.lua --- plugins/banhammer.lua | 221 ------------------------------------------ 1 file changed, 221 deletions(-) delete mode 100644 plugins/banhammer.lua diff --git a/plugins/banhammer.lua b/plugins/banhammer.lua deleted file mode 100644 index b8e5310..0000000 --- a/plugins/banhammer.lua +++ /dev/null @@ -1,221 +0,0 @@ -local function is_user_whitelisted(id) - local hash = 'whitelist:user#id'..id - local white = redis:get(hash) or false - return white -end - -local function is_chat_whitelisted(id) - local hash = 'whitelist:chat#id'..id - local white = redis:get(hash) or false - return white -end - -local function kick_user(user_id, chat_id) - local chat = 'chat#id'..chat_id - local user = 'user#id'..user_id - - if user_id == tostring(our_id) then - send_msg(chat, "I won't kick myself!", ok_cb, true) - else - chat_del_user(chat, user, ok_cb, true) - end -end - -local function ban_user(user_id, chat_id) - local chat = 'chat#id'..chat_id - if user_id == tostring(our_id) then - send_msg(chat, "I won't kick myself!", ok_cb, true) - else - -- Save to redis - local hash = 'banned:'..chat_id..':'..user_id - redis:set(hash, true) - -- Kick from chat - kick_user(user_id, chat_id) - end -end - -local function is_banned(user_id, chat_id) - local hash = 'banned:'..chat_id..':'..user_id - local banned = redis:get(hash) - return banned or false -end - -local function pre_process(msg) - - -- SERVICE MESSAGE - if msg.action and msg.action.type then - local action = msg.action.type - -- Check if banned user joins chat - if action == 'chat_add_user' or action == 'chat_add_user_link' then - local user_id - if msg.action.link_issuer then - user_id = msg.from.id - else - user_id = msg.action.user.id - end - print('Checking invited user '..user_id) - local banned = is_banned(user_id, msg.to.id) - if banned then - print('User is banned!') - kick_user(user_id, msg.to.id) - end - end - -- No further checks - return msg - end - - -- BANNED USER TALKING - if msg.to.type == 'chat' then - local user_id = msg.from.id - local chat_id = msg.to.id - local banned = is_banned(user_id, chat_id) - if banned then - print('Banned user talking!') - ban_user(user_id, chat_id) - msg.text = '' - end - end - - -- WHITELIST - local hash = 'whitelist:enabled' - local whitelist = redis:get(hash) - local issudo = is_sudo(msg) - - -- Allow all sudo users even if whitelist is allowed - if whitelist and not issudo then - print('Whitelist enabled and not sudo') - -- Check if user or chat is whitelisted - local allowed = is_user_whitelisted(msg.from.id) - - if not allowed then - print('User '..msg.from.id..' not whitelisted') - if msg.to.type == 'chat' then - allowed = is_chat_whitelisted(msg.to.id) - if not allowed then - print ('Chat '..msg.to.id..' not whitelisted') - else - print ('Chat '..msg.to.id..' whitelisted :)') - end - end - else - print('User '..msg.from.id..' allowed :)') - end - - if not allowed then - msg.text = '' - end - - else - print('Whitelist not enabled or is sudo') - end - - return msg -end - -local function run(msg, matches) - - -- Silent ignore - if not is_sudo(msg) then - return nil - end - - if matches[1] == 'ban' then - local user_id = matches[3] - local chat_id = msg.to.id - - if msg.to.type == 'chat' then - if matches[2] == 'user' then - ban_user(user_id, chat_id) - return 'User '..user_id..' banned' - end - if matches[2] == 'delete' then - local hash = 'banned:'..chat_id..':'..user_id - redis:del(hash) - return 'User '..user_id..' unbanned' - end - else - return 'This isn\'t a chat group' - end - end - - if matches[1] == 'kick' then - if msg.to.type == 'chat' then - kick_user(matches[2], msg.to.id) - else - return 'This isn\'t a chat group' - end - end - - if matches[1] == 'whitelist' then - if matches[2] == 'enable' then - local hash = 'whitelist:enabled' - redis:set(hash, true) - return 'Enabled whitelist' - end - - if matches[2] == 'disable' then - local hash = 'whitelist:enabled' - redis:del(hash) - return 'Disabled whitelist' - end - - if matches[2] == 'user' then - local hash = 'whitelist:user#id'..matches[3] - redis:set(hash, true) - return 'User '..matches[3]..' whitelisted' - end - - if matches[2] == 'chat' then - if msg.to.type ~= 'chat' then - return 'This isn\'t a chat group' - end - local hash = 'whitelist:chat#id'..msg.to.id - redis:set(hash, true) - return 'Chat '..msg.to.id..' whitelisted' - end - - if matches[2] == 'delete' and matches[3] == 'user' then - local hash = 'whitelist:user#id'..matches[4] - redis:del(hash) - return 'User '..matches[4]..' removed from whitelist' - end - - if matches[2] == 'delete' and matches[3] == 'chat' then - if msg.to.type ~= 'chat' then - return 'This isn\'t a chat group' - end - local hash = 'whitelist:chat#id'..msg.to.id - redis:del(hash) - return 'Chat '..msg.to.id..' removed from whitelist' - end - - end -end - -return { - description = "Plugin to manage bans, kicks and white/black lists.", - usage = { - "!whitelist /: Enable or disable whitelist mode", - "!whitelist user : Allow user to use the bot when whitelist mode is enabled", - "!whitelist chat: Allow everybody on current chat to use the bot when whitelist mode is enabled", - "!whitelist delete user : Remove user from whitelist", - "!whitelist delete chat: Remove chat from whitelist", - "!ban user : Kick user from chat and kicks it if joins chat again", - "!ban delete : Unban user", - "!kick Kick user from chat group" - }, - patterns = { - "^!(whitelist) (enable)$", - "^!(whitelist) (disable)$", - "^!(whitelist) (user) (%d+)$", - "^!(whitelist) (chat)$", - "^!(whitelist) (delete) (user) (%d+)$", - "^!(whitelist) (delete) (chat)$", - "^!(ban) (user) (%d+)$", - "^!(ban) (delete) (%d+)$", - "^!(kick) (%d+)$", - "^!!tgservice (.+)$", - }, - run = run, - pre_process = pre_process -} From 0ff832e9ceb6f843ef42f64febfeb6fc2f824d95 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:16:54 +0330 Subject: [PATCH 043/102] Delete boobs.lua --- plugins/boobs.lua | 72 ----------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 plugins/boobs.lua diff --git a/plugins/boobs.lua b/plugins/boobs.lua deleted file mode 100644 index b6fc356..0000000 --- a/plugins/boobs.lua +++ /dev/null @@ -1,72 +0,0 @@ -do - --- Recursive function -local function getRandomButts(attempt) - attempt = attempt or 0 - attempt = attempt + 1 - - local res,status = http.request("http://api.obutts.ru/noise/1") - - if status ~= 200 then return nil end - local data = json:decode(res)[1] - - -- The OpenBoobs API sometimes returns an empty array - if not data and attempt <= 3 then - print('Cannot get that butts, trying another one...') - return getRandomButts(attempt) - end - - return 'http://media.obutts.ru/' .. data.preview -end - -local function getRandomBoobs(attempt) - attempt = attempt or 0 - attempt = attempt + 1 - - local res,status = http.request("http://api.oboobs.ru/noise/1") - - if status ~= 200 then return nil end - local data = json:decode(res)[1] - - -- The OpenBoobs API sometimes returns an empty array - if not data and attempt < 10 then - print('Cannot get that boobs, trying another one...') - return getRandomBoobs(attempt) - end - - return 'http://media.oboobs.ru/' .. data.preview -end - -local function run(msg, matches) - local url = nil - - if matches[1] == "!boobs" then - url = getRandomBoobs() - end - - if matches[1] == "!butts" then - url = getRandomButts() - end - - if url ~= nil then - local receiver = get_receiver(msg) - send_photo_from_url(receiver, url) - else - return 'Error getting boobs/butts for you, please try again later.' - end -end - -return { - description = "Gets a random boobs or butts pic", - usage = { - "!boobs: Get a boobs NSFW image. 🔞", - "!butts: Get a butts NSFW image. 🔞" - }, - patterns = { - "^!boobs$", - "^!butts$" - }, - run = run -} - -end From 8ea7adb50a81e0f3fd3fe07c19009eae49befe29 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:16:56 +0330 Subject: [PATCH 044/102] Delete btc.lua --- plugins/btc.lua | 52 ------------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 plugins/btc.lua diff --git a/plugins/btc.lua b/plugins/btc.lua deleted file mode 100644 index 8183070..0000000 --- a/plugins/btc.lua +++ /dev/null @@ -1,52 +0,0 @@ --- See https://bitcoinaverage.com/api -local function getBTCX(amount,currency) - local base_url = 'https://api.bitcoinaverage.com/ticker/global/' - -- Do request on bitcoinaverage, the final / is critical! - local res,code = https.request(base_url..currency.."/") - - if code ~= 200 then return nil end - local data = json:decode(res) - - -- Easy, it's right there - text = "BTC/"..currency..'\n'..'Buy: '..data.ask..'\n'..'Sell: '..data.bid - - -- If we have a number as second parameter, calculate the bitcoin amount - if amount~=nil then - btc = tonumber(amount) / tonumber(data.ask) - text = text.."\n "..currency .." "..amount.." = BTC "..btc - end - return text -end - -local function run(msg, matches) - local cur = 'EUR' - local amt = nil - - -- Get the global match out of the way - if matches[1] == "!btc" then - return getBTCX(amt,cur) - end - - if matches[2] ~= nil then - -- There is a second match - amt = matches[2] - cur = string.upper(matches[1]) - else - -- Just a EUR or USD param - cur = string.upper(matches[1]) - end - return getBTCX(amt,cur) -end - -return { - description = "Bitcoin global average market value (in EUR or USD)", - usage = "!btc [EUR|USD] [amount]", - patterns = { - "^!btc$", - "^!btc ([Ee][Uu][Rr])$", - "^!btc ([Uu][Ss][Dd])$", - "^!btc (EUR) (%d+[%d%.]*)$", - "^!btc (USD) (%d+[%d%.]*)$" - }, - run = run -} From 7f6ff8e3b122d14622d818b452cfd8fb448b341f Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:17:01 +0330 Subject: [PATCH 045/102] Delete calculator.lua --- plugins/calculator.lua | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 plugins/calculator.lua diff --git a/plugins/calculator.lua b/plugins/calculator.lua deleted file mode 100644 index 72e88ac..0000000 --- a/plugins/calculator.lua +++ /dev/null @@ -1,31 +0,0 @@ --- Function reference: http://mathjs.org/docs/reference/functions/categorical.html - -local function mathjs(exp) - local url = 'http://api.mathjs.org/v1/' - url = url..'?expr='..URL.escape(exp) - local b,c = http.request(url) - local text = nil - if c == 200 then - text = 'Result: '..b - - elseif c == 400 then - text = b - else - text = 'Unexpected error\n' - ..'Is api.mathjs.org up?' - end - return text -end - -local function run(msg, matches) - return mathjs(matches[1]) -end - -return { - description = "Calculate math expressions with mathjs API", - usage = "!calc [expression]: evaluates the expression and sends the result.", - patterns = { - "^!calc (.*)$" - }, - run = run -} From bcd807cfcac8c203a5a5d6e4e8b87d7a84c7e678 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:17:08 +0330 Subject: [PATCH 046/102] Delete weather.lua --- plugins/weather.lua | 61 --------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 plugins/weather.lua diff --git a/plugins/weather.lua b/plugins/weather.lua deleted file mode 100644 index c0a6fe5..0000000 --- a/plugins/weather.lua +++ /dev/null @@ -1,61 +0,0 @@ -do - -local BASE_URL = "http://api.openweathermap.org/data/2.5/weather" - -local function get_weather(location) - print("Finding weather in ", location) - location = string.gsub(location," ","+") - local url = BASE_URL - url = url..'?q='..location - url = url..'&units=metric' - url = url..'&appid=bd82977b86bf27fb59a04b61b657fb6f' - - local b, c, h = http.request(url) - if c ~= 200 then return nil end - - local weather = json:decode(b) - local city = weather.name - local country = weather.sys.country - local temp = 'The temperature in '..city - ..' (' ..country..')' - ..' is '..weather.main.temp..'°C' - local conditions = 'Current conditions are: ' - .. weather.weather[1].description - - if weather.weather[1].main == 'Clear' then - conditions = conditions .. ' ☀' - elseif weather.weather[1].main == 'Clouds' then - conditions = conditions .. ' ☁☁' - elseif weather.weather[1].main == 'Rain' then - conditions = conditions .. ' ☔' - elseif weather.weather[1].main == 'Thunderstorm' then - conditions = conditions .. ' ☔☔☔☔' - end - - return temp .. '\n' .. conditions -end - -local function run(msg, matches) - local city = 'Madrid,ES' - - if matches[1] ~= '!weather' then - city = matches[1] - end - local text = get_weather(city) - if not text then - text = 'Can\'t get weather from that city.' - end - return text -end - -return { - description = "weather in that city (Madrid is default)", - usage = "!weather (city)", - patterns = { - "^!weather$", - "^!weather (.*)$" - }, - run = run -} - -end From 50c0805bab68423f0a5a19635b47055d370d6e53 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:19:26 +0330 Subject: [PATCH 047/102] Delete vote.lua --- plugins/vote.lua | 88 ------------------------------------------------ 1 file changed, 88 deletions(-) delete mode 100644 plugins/vote.lua diff --git a/plugins/vote.lua b/plugins/vote.lua deleted file mode 100644 index bd5ffe3..0000000 --- a/plugins/vote.lua +++ /dev/null @@ -1,88 +0,0 @@ -do - -local _file_votes = './data/votes.lua' - -function read_file_votes () - local f = io.open(_file_votes, "r+") - if f == nil then - print ('Created voting file '.._file_votes) - serialize_to_file({}, _file_votes) - else - print ('Values loaded: '.._file_votes) - f:close() - end - return loadfile (_file_votes)() -end - -function clear_votes (chat) - local _votes = read_file_votes () - _votes [chat] = {} - serialize_to_file(_votes, _file_votes) -end - -function votes_result (chat) - local _votes = read_file_votes () - local results = {} - local result_string = "" - if _votes [chat] == nil then - _votes[chat] = {} - end - for user,vote in pairs (_votes[chat]) do - if (results [vote] == nil) then - results [vote] = user - else - results [vote] = results [vote] .. ", " .. user - end - end - for vote,users in pairs (results) do - result_string = result_string .. vote .. " : " .. users .. "\n" - end - return result_string -end - - -function save_vote(chat, user, vote) - local _votes = read_file_votes () - if _votes[chat] == nil then - _votes[chat] = {} - end - _votes[chat][user] = vote - - serialize_to_file(_votes, _file_votes) - -end - -function run(msg, matches) - if (matches[1] == "ing") then - if (matches [2] == "reset") then - clear_votes (tostring(msg.to.id)) - return "Voting statistics reset.." - elseif (matches [2] == "stats") then - local votes_result = votes_result (tostring(msg.to.id)) - if (votes_result == "") then - votes_result = "[No votes registered]\n" - end - return "Voting statistics :\n" .. votes_result - end - else - save_vote(tostring(msg.to.id), msg.from.print_name, tostring(tonumber(matches[2]))) - return "Vote registered : " .. msg.from.print_name .. " " .. tostring(tonumber(matches [2])) - end -end - -return { - description = "Plugin for voting in groups.", - usage = { - "!voting reset: Reset all the votes.", - "!vote [number]: Cast the vote.", - "!voting stats: Shows the statistics of voting." - }, - patterns = { - "^!vot(ing) (reset)", - "^!vot(ing) (stats)", - "^!vot(e) ([0-9]+)$" - }, - run = run -} - -end \ No newline at end of file From ab252f77ea5e56fd2c8f7b6e6efc0bb1cc4c55bc Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:19:30 +0330 Subject: [PATCH 048/102] Delete version.lua --- plugins/version.lua | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 plugins/version.lua diff --git a/plugins/version.lua b/plugins/version.lua deleted file mode 100644 index eeb7833..0000000 --- a/plugins/version.lua +++ /dev/null @@ -1,18 +0,0 @@ -do - -function run(msg, matches) - return 'Telegram Bot '.. VERSION .. [[ - Checkout http://git.io/6jdjGg - GNU GPL v2 license.]] -end - -return { - description = "Shows bot version", - usage = "!version: Shows bot version", - patterns = { - "^!version$" - }, - run = run -} - -end From 50a461c1ee894b4426197c72d70f63799f71e867 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:19:33 +0330 Subject: [PATCH 049/102] Delete twitter_send.lua --- plugins/twitter_send.lua | 54 ---------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 plugins/twitter_send.lua diff --git a/plugins/twitter_send.lua b/plugins/twitter_send.lua deleted file mode 100644 index 2ea9349..0000000 --- a/plugins/twitter_send.lua +++ /dev/null @@ -1,54 +0,0 @@ -do - -local OAuth = require "OAuth" - -local consumer_key = "" -local consumer_secret = "" -local access_token = "" -local access_token_secret = "" - -local client = OAuth.new(consumer_key, consumer_secret, { - RequestToken = "https://api.twitter.com/oauth/request_token", - AuthorizeUser = {"https://api.twitter.com/oauth/authorize", method = "GET"}, - AccessToken = "https://api.twitter.com/oauth/access_token" - }, { - OAuthToken = access_token, - OAuthTokenSecret = access_token_secret -}) - -function run(msg, matches) - if consumer_key:isempty() then - return "Twitter Consumer Key is empty, write it in plugins/twitter_send.lua" - end - if consumer_secret:isempty() then - return "Twitter Consumer Secret is empty, write it in plugins/twitter_send.lua" - end - if access_token:isempty() then - return "Twitter Access Token is empty, write it in plugins/twitter_send.lua" - end - if access_token_secret:isempty() then - return "Twitter Access Token Secret is empty, write it in plugins/twitter_send.lua" - end - - if not is_sudo(msg) then - return "You aren't allowed to send tweets" - end - - local response_code, response_headers, response_status_line, response_body = - client:PerformRequest("POST", "https://api.twitter.com/1.1/statuses/update.json", { - status = matches[1] - }) - if response_code ~= 200 then - return "Error: "..response_code - end - return "Tweet sent" -end - -return { - description = "Sends a tweet", - usage = "!tw [text]: Sends the Tweet with the configured account.", - patterns = {"^!tw (.+)"}, - run = run -} - -end From b79240fc45896f74204851b1aae0d1fc14c17b7f Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:19:35 +0330 Subject: [PATCH 050/102] Delete twitter.lua --- plugins/twitter.lua | 76 --------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 plugins/twitter.lua diff --git a/plugins/twitter.lua b/plugins/twitter.lua deleted file mode 100644 index 8ad028e..0000000 --- a/plugins/twitter.lua +++ /dev/null @@ -1,76 +0,0 @@ -local OAuth = require "OAuth" - --- EDIT data/twitter.lua with the API keys -local twitter_config = load_from_file('data/twitter.lua', { - -- DON'T EDIT HERE. - consumer_key = "", consumer_secret = "", - access_token = "", access_token_secret = "" - }) - -local client = OAuth.new(twitter_config.consumer_key, twitter_config.consumer_secret, { - RequestToken = "https://api.twitter.com/oauth/request_token", - AuthorizeUser = {"https://api.twitter.com/oauth/authorize", method = "GET"}, - AccessToken = "https://api.twitter.com/oauth/twitter_config.access_token" -}, { - OAuthToken = twitter_config.access_token, - OAuthTokenSecret = twitter_config.access_token_secret -}) - -function run(msg, matches) - - if twitter_config.consumer_key:isempty() then - return "Twitter Consumer Key is empty, write it in plugins/twitter.lua" - end - if twitter_config.consumer_secret:isempty() then - return "Twitter Consumer Secret is empty, write it in plugins/twitter.lua" - end - if twitter_config.access_token:isempty() then - return "Twitter Access Token is empty, write it in plugins/twitter.lua" - end - if twitter_config.access_token_secret:isempty() then - return "Twitter Access Token Secret is empty, write it in plugins/twitter.lua" - end - - local twitter_url = "https://api.twitter.com/1.1/statuses/show/" .. matches[1] .. ".json" - local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url) - local response = json:decode(response_body) - - local header = "Tweet from " .. response.user.name .. " (@" .. response.user.screen_name .. ")\n" - local text = response.text - - -- replace short URLs - if response.entities.url then - for k, v in pairs(response.entities.urls) do - local short = v.url - local long = v.expanded_url - text = text:gsub(short, long) - end - end - - -- remove images - local images = {} - if response.extended_entities and response.extended_entities.media then - for k, v in pairs(response.extended_entities.media) do - local url = v.url - local pic = v.media_url - text = text:gsub(url, "") - table.insert(images, pic) - end - end - - -- send the parts - local receiver = get_receiver(msg) - send_msg(receiver, header .. "\n" .. text, ok_cb, false) - send_photos_from_url(receiver, images) - return nil -end - - -return { - description = "When user sends twitter URL, send text and images to origin. Requires OAuth Key.", - usage = "", - patterns = { - "https://twitter.com/[^/]+/status/([0-9]+)" - }, - run = run -} From 3a15928fc6a046ebdc1f040ecc47ee588658b1bc Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:19:42 +0330 Subject: [PATCH 051/102] Delete tweet.lua --- plugins/tweet.lua | 252 ---------------------------------------------- 1 file changed, 252 deletions(-) delete mode 100644 plugins/tweet.lua diff --git a/plugins/tweet.lua b/plugins/tweet.lua deleted file mode 100644 index 3b59918..0000000 --- a/plugins/tweet.lua +++ /dev/null @@ -1,252 +0,0 @@ -local OAuth = require "OAuth" - -local consumer_key = "" -local consumer_secret = "" -local access_token = "" -local access_token_secret = "" - -local twitter_url = "https://api.twitter.com/1.1/statuses/user_timeline.json" - -local client = OAuth.new(consumer_key, - consumer_secret, - { RequestToken = "https://api.twitter.com/oauth/request_token", - AuthorizeUser = {"https://api.twitter.com/oauth/authorize", method = "GET"}, - AccessToken = "https://api.twitter.com/oauth/access_token"}, - { OAuthToken = access_token, - OAuthTokenSecret = access_token_secret}) - - -local function send_generics_from_url_callback(cb_extra, success, result) - -- cb_extra is a table containing receiver, urls and remove_path - local receiver = cb_extra.receiver - local urls = cb_extra.urls - local remove_path = cb_extra.remove_path - local f = cb_extra.func - - -- The previously image to remove - if remove_path ~= nil then - os.remove(remove_path) - print("Deleted: "..remove_path) - end - - -- Nil or empty, exit case (no more urls) - if urls == nil or #urls == 0 then - return false - end - - -- Take the head and remove from urls table - local head = table.remove(urls, 1) - - local file_path = download_to_file(head, false) - local cb_extra = { - receiver = receiver, - urls = urls, - remove_path = file_path, - func = f - } - - -- Send first and postpone the others as callback - f(receiver, file_path, send_generics_from_url_callback, cb_extra) -end - -local function send_generics_from_url(f, receiver, urls) - local cb_extra = { - receiver = receiver, - urls = urls, - remove_path = nil, - func = f - } - send_generics_from_url_callback(cb_extra) -end - -local function send_gifs_from_url(receiver, urls) - send_generics_from_url(send_document, receiver, urls) -end - -local function send_videos_from_url(receiver, urls) - send_generics_from_url(send_video, receiver, urls) -end - -local function send_all_files(receiver, urls) - local data = { - images = { - func = send_photos_from_url, - urls = {} - }, - gifs = { - func = send_gifs_from_url, - urls = {} - }, - videos = { - func = send_videos_from_url, - urls = {} - } - } - - local table_to_insert = nil - for i,url in pairs(urls) do - local _, _, extension = string.match(url, "(https?)://([^\\]-([^\\%.]+))$") - local mime_type = mimetype.get_content_type_no_sub(extension) - if extension == 'gif' then - table_to_insert = data.gifs.urls - elseif mime_type == 'image' then - table_to_insert = data.images.urls - elseif mime_type == 'video' then - table_to_insert = data.videos.urls - else - table_to_insert = nil - end - if table_to_insert then - table.insert(table_to_insert, url) - end - end - for k, v in pairs(data) do - if #v.urls > 0 then - end - v.func(receiver, v.urls) - end -end - -local function check_keys() - if consumer_key:isempty() then - return "Twitter Consumer Key is empty, write it in plugins/tweet.lua" - end - if consumer_secret:isempty() then - return "Twitter Consumer Secret is empty, write it in plugins/tweet.lua" - end - if access_token:isempty() then - return "Twitter Access Token is empty, write it in plugins/tweet.lua" - end - if access_token_secret:isempty() then - return "Twitter Access Token Secret is empty, write it in plugins/tweet.lua" - end - return "" -end - - -local function analyze_tweet(tweet) - local header = "Tweet from " .. tweet.user.name .. " (@" .. tweet.user.screen_name .. ")\n" -- "Link: https://twitter.com/statuses/" .. tweet.id_str - local text = tweet.text - - -- replace short URLs - if tweet.entities.url then - for k, v in pairs(tweet.entities.urls) do - local short = v.url - local long = v.expanded_url - text = text:gsub(short, long) - end - end - - -- remove urls - local urls = {} - if tweet.extended_entities and tweet.extended_entities.media then - for k, v in pairs(tweet.extended_entities.media) do - if v.video_info and v.video_info.variants then -- If it's a video! - table.insert(urls, v.video_info.variants[1].url) - else -- If not, is an image - table.insert(urls, v.media_url) - end - text = text:gsub(v.url, "") -- Replace the URL in text - end - end - - return header, text, urls -end - - -local function sendTweet(receiver, tweet) - local header, text, urls = analyze_tweet(tweet) - -- send the parts - send_msg(receiver, header .. "\n" .. text, ok_cb, false) - send_all_files(receiver, urls) - return nil -end - - -local function getTweet(msg, base, all) - local receiver = get_receiver(msg) - - local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url, base) - - if response_code ~= 200 then - return "Can't connect, maybe the user doesn't exist." - end - - local response = json:decode(response_body) - if #response == 0 then - return "Can't retrieve any tweets, sorry" - end - if all then - for i,tweet in pairs(response) do - sendTweet(receiver, tweet) - end - else - local i = math.random(#response) - local tweet = response[i] - sendTweet(receiver, tweet) - end - - return nil -end - -function isint(n) - return n==math.floor(n) -end - -local function run(msg, matches) - local checked = check_keys() - if not checked:isempty() then - return checked - end - - local base = {include_rts = 1} - - if matches[1] == 'id' then - local userid = tonumber(matches[2]) - if userid == nil or not isint(userid) then - return "The id of a user is a number, check this web: http://gettwitterid.com/" - end - base.user_id = userid - elseif matches[1] == 'name' then - base.screen_name = matches[2] - else - return "" - end - - local count = 200 - local all = false - if #matches > 2 and matches[3] == 'last' then - count = 1 - if #matches == 4 then - local n = tonumber(matches[4]) - if n > 10 then - return "You only can ask for 10 tweets at most" - end - count = matches[4] - all = true - end - end - base.count = count - - return getTweet(msg, base, all) -end - - -return { - description = "Random tweet from user", - usage = { - "!tweet id [id]: Get a random tweet from the user with that ID", - "!tweet id [id] last: Get a random tweet from the user with that ID", - "!tweet name [name]: Get a random tweet from the user with that name", - "!tweet name [name] last: Get a random tweet from the user with that name" - }, - patterns = { - "^!tweet (id) ([%w_%.%-]+)$", - "^!tweet (id) ([%w_%.%-]+) (last)$", - "^!tweet (id) ([%w_%.%-]+) (last) ([%d]+)$", - "^!tweet (name) ([%w_%.%-]+)$", - "^!tweet (name) ([%w_%.%-]+) (last)$", - "^!tweet (name) ([%w_%.%-]+) (last) ([%d]+)$" - }, - run = run -} From fc4e2958b65d62da7ebedd24feadb078117f7e25 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:21:16 +0330 Subject: [PATCH 052/102] Delete steam.lua --- plugins/steam.lua | 78 ----------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 plugins/steam.lua diff --git a/plugins/steam.lua b/plugins/steam.lua deleted file mode 100644 index aaf7479..0000000 --- a/plugins/steam.lua +++ /dev/null @@ -1,78 +0,0 @@ --- See https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI - -do - -local BASE_URL = 'http://store.steampowered.com/api/appdetails/' -local DESC_LENTH = 200 - -local function unescape(str) - str = string.gsub( str, '<', '<' ) - str = string.gsub( str, '>', '>' ) - str = string.gsub( str, '"', '"' ) - str = string.gsub( str, ''', "'" ) - str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end ) - str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end ) - str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others - return str -end - -local function get_steam_data (appid) - local url = BASE_URL - url = url..'?appids='..appid - url = url..'&cc=us' - local res,code = http.request(url) - if code ~= 200 then return nil end - local data = json:decode(res)[appid].data - return data -end - -local function price_info (data) - local price = '' -- If no data is empty - - if data then - local initial = data.initial - local final = data.final or data.initial - local min = math.min(data.initial, data.final) - price = tostring(min/100) - if data.discount_percent and initial ~= final then - price = price..data.currency..' ('..data.discount_percent..'% OFF)' - end - price = price..' (US)' - end - - return price -end - - -local function send_steam_data(data, receiver) - local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...' - local title = data.name - local price = price_info(data.price_overview) - - local text = title..' '..price..'\n'..description - local image_url = data.header_image - local cb_extra = { - receiver = receiver, - url = image_url - } - send_msg(receiver, text, send_photo_from_url_callback, cb_extra) -end - - -local function run(msg, matches) - local appid = matches[1] - local data = get_steam_data(appid) - local receiver = get_receiver(msg) - send_steam_data(data, receiver) -end - -return { - description = "Grabs Steam info for Steam links.", - usage = "", - patterns = { - "http://store.steampowered.com/app/([0-9]+)", - }, - run = run -} - -end From ce026118fbc76e30f29fdb7d6d3efaadfee23153 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:21:22 +0330 Subject: [PATCH 053/102] Delete torrent_search.lua --- plugins/torrent_search.lua | 48 -------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 plugins/torrent_search.lua diff --git a/plugins/torrent_search.lua b/plugins/torrent_search.lua deleted file mode 100644 index 6038390..0000000 --- a/plugins/torrent_search.lua +++ /dev/null @@ -1,48 +0,0 @@ -local https = require ('ssl.https') -local ltn12 = require ("ltn12") - -local function search_kickass(query) - local url = 'https://kat.cr/json.php?q='..URL.escape(query) - - local resp = {} - - local b,c = https.request - { - url = url, - protocol = "tlsv1", - sink = ltn12.sink.table(resp) - } - - resp = table.concat(resp) - - local data = json:decode(resp) - - local text = 'Results: '..data.total_results..'\n\n' - local results = math.min(#data.list, 5) - for i=1,results do - local torrent = data.list[i] - local link = torrent.torrentLink - link = link:gsub('%?title=.+','') - text = text..torrent.title - ..'\n'..'Seeds: '..torrent.seeds - ..' '..'Leeches: '..torrent.leechs - ..'\n'..link - --..'\n magnet:?xt=urn:btih:'..torrent.hash - ..'\n\n' - end - return text -end - -local function run(msg, matches) - local query = matches[1] - return search_kickass(query) -end - -return { - description = "Search Torrents", - usage = "!torrent : Search for torrent", - patterns = { - "^!torrent (.+)$" - }, - run = run -} From 3533f4350979797083335042ce91b352c8a13ce4 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:21:25 +0330 Subject: [PATCH 054/102] Delete remind.lua --- plugins/remind.lua | 78 ---------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 plugins/remind.lua diff --git a/plugins/remind.lua b/plugins/remind.lua deleted file mode 100644 index 2ae7165..0000000 --- a/plugins/remind.lua +++ /dev/null @@ -1,78 +0,0 @@ -local filename='data/remind.lua' -local cronned = load_from_file(filename) - -local function save_cron(msg, text,date) - local origin = get_receiver(msg) - if not cronned[date] then - cronned[date] = {} - end - local arr = { origin, text } ; - table.insert(cronned[date], arr) - serialize_to_file(cronned, filename) - return 'Saved!' -end - -local function delete_cron(date) - for k,v in pairs(cronned) do - if k == date then - cronned[k]=nil - end - end - serialize_to_file(cronned, filename) -end - -local function cron() - for date, values in pairs(cronned) do - if date < os.time() then --time's up - send_msg(values[1][1], "Time's up:"..values[1][2], ok_cb, false) - delete_cron(date) --TODO: Maybe check for something else? Like user - end - - end -end - -local function actually_run(msg, delay,text) - if (not delay or not text) then - return "Usage: !remind [delay: 2h3m1s] text" - end - save_cron(msg, text,delay) - return "I'll remind you on " .. os.date("%x at %H:%M:%S",delay) .. " about '" .. text .. "'" -end - -local function run(msg, matches) - local sum = 0 - for i = 1, #matches-1 do - local b,_ = string.gsub(matches[i],"[a-zA-Z]","") - if string.find(matches[i], "s") then - sum=sum+b - end - if string.find(matches[i], "m") then - sum=sum+b*60 - end - if string.find(matches[i], "h") then - sum=sum+b*3600 - end - end - - local date=sum+os.time() - local text = matches[#matches] - - local text = actually_run(msg, date, text) - return text -end - -return { - description = "remind plugin", - usage = { - "!remind [delay: 2hms] text", - "!remind [delay: 2h3m] text", - "!remind [delay: 2h3m1s] text" - }, - patterns = { - "^!remind ([0-9]+[hmsdHMSD]) (.+)$", - "^!remind ([0-9]+[hmsdHMSD])([0-9]+[hmsdHMSD]) (.+)$", - "^!remind ([0-9]+[hmsdHMSD])([0-9]+[hmsdHMSD])([0-9]+[hmsdHMSD]) (.+)$" - }, - run = run, - cron = cron -} From e8f9b18368b32a867182abdcd226e563f386dfe8 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:21:29 +0330 Subject: [PATCH 055/102] Delete eur.lua --- plugins/eur.lua | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 plugins/eur.lua diff --git a/plugins/eur.lua b/plugins/eur.lua deleted file mode 100644 index fac860a..0000000 --- a/plugins/eur.lua +++ /dev/null @@ -1,38 +0,0 @@ -do --- TODO: More currencies - --- See http://webrates.truefx.com/rates/connect.html -local function getEURUSD(usd) - local url = 'http://webrates.truefx.com/rates/connect.html?c=EUR/USD&f=csv&s=n' - local res,code = http.request(url) - local rates = res:split(", ") - local symbol = rates[1] - local timestamp = rates[2] - local sell = rates[3]..rates[4] - local buy = rates[5]..rates[6] - local text = symbol..'\n'..'Buy: '..buy..'\n'..'Sell: '..sell - if usd then - local eur = tonumber(usd) / tonumber(buy) - text = text.."\n "..usd.."USD = "..eur.."EUR" - end - return text -end - -local function run(msg, matches) - if matches[1] == "!eur" then - return getEURUSD(nil) - end - return getEURUSD(matches[1]) -end - -return { - description = "Real-time EURUSD market price", - usage = "!eur [USD]", - patterns = { - "^!eur$", - "^!eur (%d+[%d%.]*)$", - }, - run = run -} - -end \ No newline at end of file From 310859e29aa2dae6c90e44f8f79e8c6fe3543dd6 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:21:32 +0330 Subject: [PATCH 056/102] Delete dogify.lua --- plugins/dogify.lua | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 plugins/dogify.lua diff --git a/plugins/dogify.lua b/plugins/dogify.lua deleted file mode 100644 index 4c46123..0000000 --- a/plugins/dogify.lua +++ /dev/null @@ -1,24 +0,0 @@ -local function run(msg, matches) - local base = "http://dogr.io/" - local path = string.gsub(matches[1], " ", "%%20") - local url = base .. path .. '.png?split=false&.png' - local urlm = "https?://[%%%w-_%.%?%.:/%+=&]+" - - if string.match(url, urlm) == url then - local receiver = get_receiver(msg) - send_photo_from_url(receiver, url) - else - print("Can't build a good URL with parameter " .. matches[1]) - end -end - -return { - description = "Create a doge image with you words", - usage = { - "!dogify (your/words/with/slashes): Create a doge with the image and words" - }, - patterns = { - "^!dogify (.+)$", - }, - run = run -} From 044c70edfd43a6127f910d48e7247503aee0fb99 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:21:35 +0330 Subject: [PATCH 057/102] Delete danbooru.lua --- plugins/danbooru.lua | 74 -------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 plugins/danbooru.lua diff --git a/plugins/danbooru.lua b/plugins/danbooru.lua deleted file mode 100644 index b0e6c64..0000000 --- a/plugins/danbooru.lua +++ /dev/null @@ -1,74 +0,0 @@ -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" - -local function get_post(url) - local b, c, h = http.request(url) - if c ~= 200 then return nil end - local posts = json:decode(b) - - return posts[math.random(#posts)] -end - -local function run(msg, matches) - - local url = URL - - if matches[1] == "!danbooru" then - url = url .. URL_NEW - else - url = url .. URL_POP - - if matches[1] == "d" then - url = url .. scale_day - elseif matches[1] == "w" then - url = url .. scale_week - elseif matches[1] == "m" then - url = url .. scale_month - end - end - - local post = get_post(url) - - if post then - vardump(post) - local img = URL .. post.large_file_url - send_photo_from_url(get_receiver(msg), img) - - local txt = '' - if post.tag_string_artist ~= '' then - txt = 'Artist: ' .. post.tag_string_artist .. '\n' - end - if post.tag_string_character ~= '' then - txt = txt .. 'Character: ' .. post.tag_string_character .. '\n' - end - if post.file_size ~= '' then - txt = txt .. '[' .. math.ceil(post.file_size/1000) .. 'kb] ' .. URL .. post.file_url - end - return txt - end -end - -return { - description = "Gets a random fresh or popular image from Danbooru", - usage = { - "!danbooru - gets a random fresh image from Danbooru 🔞", - "!danboorud - random daily popular image 🔞", - "!danbooruw - random weekly popular image 🔞", - "!danboorum - random monthly popular image 🔞" - }, - patterns = { - "^!danbooru$", - "^!danbooru ?(d)$", - "^!danbooru ?(w)$", - "^!danbooru ?(m)$" - }, - run = run -} - -end \ No newline at end of file From 55cf8f2efb163a1935df9d14ceaa0bac28a7a907 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:21:38 +0330 Subject: [PATCH 058/102] Delete chuck_norris.lua --- plugins/chuck_norris.lua | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 plugins/chuck_norris.lua diff --git a/plugins/chuck_norris.lua b/plugins/chuck_norris.lua deleted file mode 100644 index 60e3788..0000000 --- a/plugins/chuck_norris.lua +++ /dev/null @@ -1,36 +0,0 @@ -do - - local function unescape(str) - str = string.gsub( str, '<', '<' ) - str = string.gsub( str, '>', '>' ) - str = string.gsub( str, '"', '"' ) - str = string.gsub( str, ''', "'" ) - str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end ) - str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end ) - str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others - return str - end - - local function chuck() - local random = http.request("http://api.icndb.com/jokes/random") - local decode = json:decode(random) - local joke = decode.value.joke - local unescape = unescape(joke) - return unescape - end - - function run(msg) - local joke = chuck() - return joke - end - - return { - description = "Get random Chuck Norris jokes.", - usage = "!chuck", - patterns = { - "^!chuck$" - }, - run = run -} - -end From faab24a00b6ce10cacbc3ea340386dca52709a7e Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:21:42 +0330 Subject: [PATCH 059/102] Delete channels.lua --- plugins/channels.lua | 80 -------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 plugins/channels.lua diff --git a/plugins/channels.lua b/plugins/channels.lua deleted file mode 100644 index 8d7e710..0000000 --- a/plugins/channels.lua +++ /dev/null @@ -1,80 +0,0 @@ --- Checks if bot was disabled on specific chat -local function is_channel_disabled( receiver ) - if not _config.disabled_channels then - return false - end - - if _config.disabled_channels[receiver] == nil then - return false - end - - return _config.disabled_channels[receiver] -end - -local function enable_channel(receiver) - if not _config.disabled_channels then - _config.disabled_channels = {} - end - - if _config.disabled_channels[receiver] == nil then - return 'Channel isn\'t disabled' - end - - _config.disabled_channels[receiver] = false - - save_config() - return "Channel re-enabled" -end - -local function disable_channel( receiver ) - if not _config.disabled_channels then - _config.disabled_channels = {} - end - - _config.disabled_channels[receiver] = true - - save_config() - return "Channel disabled" -end - -local function pre_process(msg) - local receiver = get_receiver(msg) - - -- If sender is sudo then re-enable the channel - if is_sudo(msg) then - if msg.text == "!channel enable" then - enable_channel(receiver) - end - end - - if is_channel_disabled(receiver) then - msg.text = "" - end - - return msg -end - -local function run(msg, matches) - local receiver = get_receiver(msg) - -- Enable a channel - if matches[1] == 'enable' then - return enable_channel(receiver) - end - -- Disable a channel - if matches[1] == 'disable' then - return disable_channel(receiver) - end -end - -return { - description = "Plugin to manage channels. Enable or disable channel.", - usage = { - "!channel enable: enable current channel", - "!channel disable: disable current channel" }, - patterns = { - "^!channel? (enable)", - "^!channel? (disable)" }, - run = run, - privileged = true, - pre_process = pre_process -} \ No newline at end of file From 2fe4d2e6c6e72d1027a46e54adb8d41a846b8915 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:25:40 +0330 Subject: [PATCH 060/102] Delete trivia.lua --- plugins/trivia.lua | 238 --------------------------------------------- 1 file changed, 238 deletions(-) delete mode 100644 plugins/trivia.lua diff --git a/plugins/trivia.lua b/plugins/trivia.lua deleted file mode 100644 index 5f81bb0..0000000 --- a/plugins/trivia.lua +++ /dev/null @@ -1,238 +0,0 @@ -do --- Trivia plugin developed by Guy Spronck - --- Returns the chat hash for storing information -local function get_hash(msg) - local hash = nil - if msg.to.type == 'chat' then - hash = 'chat:'..msg.to.id..':trivia' - end - if msg.to.type == 'user' then - hash = 'user:'..msg.from.id..':trivia' - end - return hash -end - --- Sets the question variables -local function set_question(msg, question, answer) - local hash =get_hash(msg) - if hash then - redis:hset(hash, "question", question) - redis:hset(hash, "answer", answer) - redis:hset(hash, "time", os.time()) - end -end - --- Returns the current question -local function get_question( msg ) - local hash = get_hash(msg) - if hash then - local question = redis:hget(hash, 'question') - if question ~= "NA" then - return question - end - end - return nil -end - --- Returns the answer of the last question -local function get_answer(msg) - local hash = get_hash(msg) - if hash then - return redis:hget(hash, 'answer') - else - return nil - end -end - --- Returns the time of the last question -local function get_time(msg) - local hash = get_hash(msg) - if hash then - return redis:hget(hash, 'time') - else - return nil - end -end - --- This function generates a new question if available -local function get_newquestion(msg) - local timediff = 601 - if(get_time(msg)) then - timediff = os.time() - get_time(msg) - end - if(timediff > 600 or get_question(msg) == nil)then - -- Let's show the answer if no-body guessed it right. - if(get_question(msg)) then - send_large_msg(get_receiver(msg), "The question '" .. get_question(msg) .."' has not been answered. \nThe answer was '" .. get_answer(msg) .."'") - end - - local url = "http://jservice.io/api/random/" - local b,c = http.request(url) - local query = json:decode(b) - - if query then - local stringQuestion = "" - if(query[1].category)then - stringQuestion = "Category: " .. query[1].category.title .. "\n" - end - if query[1].question then - stringQuestion = stringQuestion .. "Question: " .. query[1].question - set_question(msg, query[1].question, query[1].answer:lower()) - return stringQuestion - end - end - return 'Something went wrong, please try again.' - else - return 'Please wait ' .. 600 - timediff .. ' seconds before requesting a new question. \nUse !triviaquestion to see the current question.' - end -end - --- This function generates a new question when forced -local function force_newquestion(msg) - -- Let's show the answer if no-body guessed it right. - if(get_question(msg)) then - send_large_msg(get_receiver(msg), "The question '" .. get_question(msg) .."' has not been answered. \nThe answer was '" .. get_answer(msg) .."'") - end - - local url = "http://jservice.io/api/random/" - local b,c = http.request(url) - local query = json:decode(b) - - if query then - local stringQuestion = "" - if(query[1].category)then - stringQuestion = "Category: " .. query[1].category.title .. "\n" - end - if query[1].question then - stringQuestion = stringQuestion .. "Question: " .. query[1].question - set_question(msg, query[1].question, query[1].answer:lower()) - return stringQuestion - end - end - return 'Something went wrong, please try again.' -end - --- This function adds a point to the player -local function give_point(msg) - local hash = get_hash(msg) - if hash then - local score = tonumber(redis:hget(hash, msg.from.id) or 0) - redis:hset(hash, msg.from.id, score+1) - end -end - --- This function checks for a correct answer -local function check_answer(msg, answer) - if(get_answer(msg)) then -- Safety for first time use - if(get_answer(msg) == "NA")then - -- Question has not been set, give a new one - --get_newquestion(msg) - return "No question set, please use !trivia first." - elseif (get_answer(msg) == answer:lower()) then -- Question is set, lets check the answer - set_question(msg, "NA", "NA") -- Correct, clear the answer - give_point(msg) -- gives out point to player for correct answer - return msg.from.print_name .. " has answered correctly! \nUse !trivia to get a new question." - else - return "Sorry " .. msg.from.print_name .. ", but '" .. answer .. "' is not the correct answer!" - end - else - return "No question set, please use !trivia first." - end -end - -local function user_print_name(user) - if user.print_name then - return user.print_name - end - - local text = '' - if user.first_name then - text = user.last_name..' ' - end - if user.lastname then - text = text..user.last_name - end - - return text -end - - -local function get_user_score(msg, user_id, chat_id) - local user_info = {} - local uhash = 'user:'..user_id - local user = redis:hgetall(uhash) - local hash = 'chat:'..msg.to.id..':trivia' - user_info.score = tonumber(redis:hget(hash, user_id) or 0) - user_info.name = user_print_name(user)..' ('..user_id..')' - return user_info -end - --- Function to print score -local function trivia_scores(msg) - if msg.to.type == 'chat' then - -- Users on chat - local hash = 'chat:'..msg.to.id..':users' - local users = redis:smembers(hash) - local users_info = {} - - -- Get user info - for i = 1, #users do - local user_id = users[i] - local user_info = get_user_score(msg, user_id, msg.to.id) - table.insert(users_info, user_info) - end - - table.sort(users_info, function(a, b) - if a.score and b.score then - return a.score > b.score - end - end) - - local text = '' - for k,user in pairs(users_info) do - text = text..user.name..' => '..user.score..'\n' - end - - return text - else - return "This function is only available in group chats." - end -end - -local function run(msg, matches) - if(matches[1] == "!triviascore" or matches[1] == "!triviascores") then - -- Output all scores - return trivia_scores(msg) - elseif(matches[1] == "!triviaquestion")then - return "Question: " .. get_question(msg) - elseif(matches[1] == "!triviaskip") then - if is_sudo(msg) then - return force_newquestion(msg) - end - elseif(matches[1] ~= "!trivia") then - return check_answer(msg, matches[1]) - end - - return get_newquestion(msg) -end - -return { - description = "Trivia plugin for Telegram", - usage = { - "!trivia to obtain a new question.", - "!trivia [answer] to answer the question.", - "!triviaquestion to show the current question.", - "!triviascore to get a scoretable of all players.", - "!triviaskip to skip a question (requires sudo)" - }, - patterns = {"^!trivia (.*)$", - "^!trivia$", - "^!triviaquestion$", - "^!triviascore$", - "^!triviascores$", - "^!triviaskip$"}, - run = run -} - -end From 355b7ebcafa2b356463798b3df554c81761e47e0 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:25:41 +0330 Subject: [PATCH 061/102] Delete translate.lua --- plugins/translate.lua | 75 ------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 plugins/translate.lua diff --git a/plugins/translate.lua b/plugins/translate.lua deleted file mode 100644 index 09d4354..0000000 --- a/plugins/translate.lua +++ /dev/null @@ -1,75 +0,0 @@ - ---[[ --- Translate text using Google Translate. --- http://translate.google.com/translate_a/single?client=t&ie=UTF-8&oe=UTF-8&hl=en&dt=t&tl=en&sl=auto&text=hello ---]] -do - -function translate(source_lang, target_lang, text) - local path = "http://translate.google.com/translate_a/single" - -- URL query parameters - local params = { - client = "t", - ie = "UTF-8", - oe = "UTF-8", - hl = "en", - dt = "t", - tl = target_lang or "en", - sl = source_lang or "auto", - text = URL.escape(text) - } - - local query = format_http_params(params, true) - local url = path..query - - local res, code = https.request(url) - -- Return nil if error - if code > 200 then return nil end - local trans = res:gmatch("%[%[%[\"(.*)\"")():gsub("\"(.*)", "") - - return trans -end - -function run(msg, matches) - -- Third pattern - if #matches == 1 then - print("First") - local text = matches[1] - return translate(nil, nil, text) - end - - -- Second pattern - if #matches == 2 then - print("Second") - local target = matches[1] - local text = matches[2] - return translate(nil, target, text) - end - - -- First pattern - if #matches == 3 then - print("Third") - local source = matches[1] - local target = matches[2] - local text = matches[3] - return translate(source, target, text) - end - -end - -return { - description = "Translate some text", - usage = { - "!translate text. Translate the text to English.", - "!translate target_lang text.", - "!translate source,target text", - }, - patterns = { - "^!translate ([%w]+),([%a]+) (.+)", - "^!translate ([%w]+) (.+)", - "^!translate (.+)", - }, - run = run -} - -end From 67a1dffdde69c98db63febe1fe5427af5499836e Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:25:44 +0330 Subject: [PATCH 062/102] Delete time.lua --- plugins/time.lua | 100 ----------------------------------------------- 1 file changed, 100 deletions(-) delete mode 100644 plugins/time.lua diff --git a/plugins/time.lua b/plugins/time.lua deleted file mode 100644 index 3ff6db6..0000000 --- a/plugins/time.lua +++ /dev/null @@ -1,100 +0,0 @@ --- Implement a command !time [area] which uses --- 2 Google APIs to get the desired result: --- 1. Geocoding to get from area to a lat/long pair --- 2. Timezone to get the local time in that lat/long location - --- Globals --- If you have a google api key for the geocoding/timezone api -api_key = nil - -base_api = "https://maps.googleapis.com/maps/api" -dateFormat = "%A %d %B - %H:%M:%S" - --- Need the utc time for the google api -function utctime() - return os.time(os.date("!*t")) -end - --- Use the geocoding api to get the lattitude and longitude with accuracy specifier --- CHECKME: this seems to work without a key?? -function get_latlong(area) - local api = base_api .. "/geocode/json?" - local parameters = "address=".. (URL.escape(area) or "") - if api_key ~= nil then - parameters = parameters .. "&key="..api_key - end - - -- Do the request - local res, code = https.request(api..parameters) - if code ~=200 then return nil end - local data = json:decode(res) - - if (data.status == "ZERO_RESULTS") then - return nil - end - if (data.status == "OK") then - -- Get the data - lat = data.results[1].geometry.location.lat - lng = data.results[1].geometry.location.lng - acc = data.results[1].geometry.location_type - types= data.results[1].types - return lat,lng,acc,types - end -end - --- Use timezone api to get the time in the lat, --- Note: this needs an API key -function get_time(lat,lng) - local api = base_api .. "/timezone/json?" - - -- Get a timestamp (server time is relevant here) - local timestamp = utctime() - local parameters = "location=" .. - URL.escape(lat) .. "," .. - URL.escape(lng) .. - "×tamp="..URL.escape(timestamp) - if api_key ~=nil then - parameters = parameters .. "&key="..api_key - end - - local res,code = https.request(api..parameters) - if code ~= 200 then return nil end - local data = json:decode(res) - - if (data.status == "ZERO_RESULTS") then - return nil - end - if (data.status == "OK") then - -- Construct what we want - -- The local time in the location is: - -- timestamp + rawOffset + dstOffset - local localTime = timestamp + data.rawOffset + data.dstOffset - return localTime, data.timeZoneId - end - return localTime -end - -function getformattedLocalTime(area) - if area == nil then - return "The time in nowhere is never" - end - - lat,lng,acc = get_latlong(area) - if lat == nil and lng == nil then - return 'It seems that in "'..area..'" they do not have a concept of time.' - end - local localTime, timeZoneId = get_time(lat,lng) - - return "The local time in "..timeZoneId.." is: ".. os.date(dateFormat,localTime) -end - -function run(msg, matches) - return getformattedLocalTime(matches[1]) -end - -return { - description = "Displays the local time in an area", - usage = "!time [area]: Displays the local time in that area", - patterns = {"^!time (.*)$"}, - run = run -} From 894196cf9472b0e6724b63ceadf1786592b27663 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:25:47 +0330 Subject: [PATCH 063/102] Delete tex.lua --- plugins/tex.lua | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 plugins/tex.lua diff --git a/plugins/tex.lua b/plugins/tex.lua deleted file mode 100644 index c87c494..0000000 --- a/plugins/tex.lua +++ /dev/null @@ -1,32 +0,0 @@ -do - -local function send_title(cb_extra, success, result) - if success then - send_msg(cb_extra[1], cb_extra[2], ok_cb, false) - end -end - -local function run(msg, matches) - local eq = URL.escape(matches[1]) - - local url = "http://latex.codecogs.com/png.download?" - .."\\dpi{300}%20\\LARGE%20"..eq - - local receiver = get_receiver(msg) - local title = "Edit LaTeX on www.codecogs.com/eqnedit.php?latex="..eq - send_photo_from_url(receiver, url, send_title, {receiver, title}) -end - -return { - description = "Convert LaTeX equation to image", - usage = { - "!tex [equation]: Convert LaTeX equation to image" - }, - patterns = { - "^!tex (.+)$" - }, - run = run -} - -end - From bc5cd207a3146a624f43d0b11f66ff042fe02760 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:26:04 +0330 Subject: [PATCH 064/102] Delete service_template.lua --- plugins/service_template.lua | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 plugins/service_template.lua diff --git a/plugins/service_template.lua b/plugins/service_template.lua deleted file mode 100644 index 108bfcf..0000000 --- a/plugins/service_template.lua +++ /dev/null @@ -1,18 +0,0 @@ -local function run(msg, matches) - -- avoid this plugins to process user messages - if not msg.service then - -- return "Are you trying to troll me?" - return nil - end - print("Service message received: " .. matches[1]) -end - - -return { - description = "Template for service plugins", - usage = "", - patterns = { - "^!!tgservice (.*)$" -- Do not use the (.*) match in your service plugin - }, - run = run -} From 8d47591f5b204cf9b4251ded31aca1eb97c8ebdd Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:26:07 +0330 Subject: [PATCH 065/102] Delete location.lua --- plugins/location.lua | 61 -------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 plugins/location.lua diff --git a/plugins/location.lua b/plugins/location.lua deleted file mode 100644 index 23663db..0000000 --- a/plugins/location.lua +++ /dev/null @@ -1,61 +0,0 @@ --- Implement a command !loc [area] which uses --- the static map API to get a location image - --- Not sure if this is the proper way --- Intent: get_latlong is in time.lua, we need it here --- loadfile "time.lua" - --- Globals --- If you have a google api key for the geocoding/timezone api -do - -local api_key = nil - -local base_api = "https://maps.googleapis.com/maps/api" - -function get_staticmap(area) - local api = base_api .. "/staticmap?" - - -- Get a sense of scale - local lat,lng,acc,types = get_latlong(area) - - local scale = types[1] - if scale=="locality" then zoom=8 - elseif scale=="country" then zoom=4 - else zoom = 13 end - - local parameters = - "size=600x300" .. - "&zoom=" .. zoom .. - "¢er=" .. URL.escape(area) .. - "&markers=color:red"..URL.escape("|"..area) - - if api_key ~=nil and api_key ~= "" then - parameters = parameters .. "&key="..api_key - end - return lat, lng, api..parameters -end - - -function run(msg, matches) - local receiver = get_receiver(msg) - local lat,lng,url = get_staticmap(matches[1]) - - -- Send the actual location, is a google maps link - send_location(receiver, lat, lng, ok_cb, false) - - -- Send a picture of the map, which takes scale into account - send_photo_from_url(receiver, url) - - -- Return a link to the google maps stuff is now not needed anymore - return nil -end - -return { - description = "Gets information about a location, maplink and overview", - usage = "!loc (location): Gets information about a location, maplink and overview", - patterns = {"^!loc (.*)$"}, - run = run -} - -end \ No newline at end of file From 03421b24cbc6ce62196cd67bdb601dd6cd1b4e2e Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:26:10 +0330 Subject: [PATCH 066/102] Delete inviteme.lua --- plugins/inviteme.lua | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 plugins/inviteme.lua diff --git a/plugins/inviteme.lua b/plugins/inviteme.lua deleted file mode 100644 index e7a092c..0000000 --- a/plugins/inviteme.lua +++ /dev/null @@ -1,24 +0,0 @@ -do - -local function parsed_url(link) - local parsed_link = URL.parse(link) - local parsed_path = URL.parse_path(parsed_link.path) - return parsed_path[2] -end - -function run(msg, matches) - local hash = parsed_url(matches[1]) - join = import_chat_link(hash,ok_cb,false) -end - - -return { - description = "Invite me into a group chat", - usage = "!inviteme [invite link]", - patterns = { - "^!inviteme (.*)$" - }, - run = run -} - -end From cdd740580ed516512235f35ea3a4740e27a85aad Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 18:26:13 +0330 Subject: [PATCH 067/102] Delete gnuplot.lua --- plugins/gnuplot.lua | 72 --------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 plugins/gnuplot.lua diff --git a/plugins/gnuplot.lua b/plugins/gnuplot.lua deleted file mode 100644 index fa05b7e..0000000 --- a/plugins/gnuplot.lua +++ /dev/null @@ -1,72 +0,0 @@ ---[[ -* Gnuplot plugin by psykomantis -* dependencies: -* - gnuplot 5.00 -* - libgd2-xpm-dev (on Debian distr) for more info visit: https://libgd.github.io/pages/faq.html -* -]] - --- Gnuplot needs absolute path for the plot, so i run some commands to find where we are -local outputFile = io.popen("pwd","r") -io.input(outputFile) -local _pwd = io.read("*line") -io.close(outputFile) -local _absolutePlotPath = _pwd .. "/data/plot.png" -local _scriptPath = "./data/gnuplotScript.gpl" - -do - -local function gnuplot(msg, fun) - local receiver = get_receiver(msg) - - -- We generate the plot commands - local formattedString = [[ - set grid - set terminal png - set output "]] .. _absolutePlotPath .. [[" - plot ]] .. fun - - local file = io.open(_scriptPath,"w"); - file:write(formattedString) - file:close() - - os.execute("gnuplot " .. _scriptPath) - os.remove (_scriptPath) - - return _send_photo(receiver, _absolutePlotPath) -end - --- Check all dependencies before executing -local function checkDependencies() - local status = os.execute("gnuplot -h") - if(status==true) then - status = os.execute("gnuplot -e 'set terminal png'") - if(status == true) then - return 0 -- OK ready to go! - else - return 1 -- missing libgd2-xpm-dev - end - else - return 2 -- missing gnuplot - end -end - -local function run(msg, matches) - local status = checkDependencies() - if(status == 0) then - return gnuplot(msg,matches[1]) - elseif(status == 1) then - return "It seems that this bot miss a dependency :/" - else - return "It seems that this bot doesn't have gnuplot :/" - end -end - -return { - description = "use gnuplot through telegram, only plot single variable function", - usage = "!gnuplot [single variable function]", - patterns = {"^!gnuplot (.+)$"}, - run = run -} - -end From a6f262c96aa9e0db036797b2032d7444e540f55d Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:12:46 +0330 Subject: [PATCH 068/102] Delete expand.lua --- plugins/expand.lua | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 plugins/expand.lua diff --git a/plugins/expand.lua b/plugins/expand.lua deleted file mode 100644 index 2986672..0000000 --- a/plugins/expand.lua +++ /dev/null @@ -1,26 +0,0 @@ -local function run(msg, patterns) - local response_body = {} - local request_constructor = { - url = patterns[1], - method = "HEAD", - sink = ltn12.sink.table(response_body), - headers = {}, - redirect = false - } - - local ok, response_code, response_headers, response_status_line = http.request(request_constructor) - if ok and response_headers.location then - return " 👍 " .. response_headers.location - else - return "Can't expand the url." - end -end - -return { - description = "Expand a shortened URL to the original one.", - usage = "!expand [url]: Return the original URL", - patterns = { - "^!expand (https?://[%w-_%.%?%.:/%+=&]+)$" - }, - run = run -} From 292dbaf9082945d8d78b55049c093e9005d57ee7 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:12:49 +0330 Subject: [PATCH 069/102] Delete face.lua --- plugins/face.lua | 92 ------------------------------------------------ 1 file changed, 92 deletions(-) delete mode 100644 plugins/face.lua diff --git a/plugins/face.lua b/plugins/face.lua deleted file mode 100644 index c229e3e..0000000 --- a/plugins/face.lua +++ /dev/null @@ -1,92 +0,0 @@ -local https = require("ssl.https") -local ltn12 = require "ltn12" - --- Edit data/mashape.lua with your Mashape API key --- http://docs.mashape.com/api-keys -local mashape = load_from_file('data/mashape.lua', { - api_key = '' - }) - -local function request(imageUrl) - local api_key = mashape.api_key - if api_key:isempty() then - return nil, 'Configure your Mashape API Key' - end - - local api = "https://faceplusplus-faceplusplus.p.mashape.com/detection/detect?" - local parameters = "attribute=gender%2Cage%2Crace" - parameters = parameters .. "&url="..(URL.escape(imageUrl) or "") - local url = api..parameters - local headers = { - ["X-Mashape-Key"] = api_key, - ["Accept"] = "Accept: application/json" - } - print(url) - local respbody = {} - local body, code = https.request{ - url = url, - method = "GET", - headers = headers, - sink = ltn12.sink.table(respbody), - protocol = "tlsv1" - } - if code ~= 200 then return "", code end - local body = table.concat(respbody) - return body, code -end - -local function parseData(data) - local jsonBody = json:decode(data) - local response = "" - if jsonBody.error ~= nil then - if jsonBody.error == "IMAGE_ERROR_FILE_TOO_LARGE" then - response = response .. "The image is too big. Provide a smaller image." - elseif jsonBody.error == "IMAGE_ERROR_FAILED_TO_DOWNLOAD" then - response = response .. "Is that a valid url for an image?" - else - response = response .. jsonBody.error - end - elseif jsonBody.face == nil or #jsonBody.face == 0 then - response = response .. "No faces found" - else - response = response .. #jsonBody.face .." face(s) found:\n\n" - for k,face in pairs(jsonBody.face) do - local raceP = "" - if face.attribute.race.confidence > 85.0 then - raceP = face.attribute.race.value:lower() - elseif face.attribute.race.confidence > 50.0 then - raceP = "(probably "..face.attribute.race.value:lower()..")" - else - raceP = "(posibly "..face.attribute.race.value:lower()..")" - end - if face.attribute.gender.confidence > 85.0 then - response = response .. "There is a " - else - response = response .. "There may be a " - end - response = response .. raceP .. " " .. face.attribute.gender.value:lower() .. " " - response = response .. ", " .. face.attribute.age.value .. "(±".. face.attribute.age.range ..") years old \n" - end - end - return response -end - -local function run(msg, matches) - --return request('http://www.uni-regensburg.de/Fakultaeten/phil_Fak_II/Psychologie/Psy_II/beautycheck/english/durchschnittsgesichter/m(01-32)_gr.jpg') - local data, code = request(matches[1]) - if code ~= 200 then return "There was an error. "..code end - return parseData(data) -end - -return { - description = "Who is in that photo?", - usage = { - "!face [url]", - "!recognise [url]" - }, - patterns = { - "^!face (.*)$", - "^!recognise (.*)$" - }, - run = run -} From 6337ffae75aab08e758da50ff940bff86d4a96c7 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:12:52 +0330 Subject: [PATCH 070/102] Delete fortunes_uc3m.lua --- plugins/fortunes_uc3m.lua | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 plugins/fortunes_uc3m.lua diff --git a/plugins/fortunes_uc3m.lua b/plugins/fortunes_uc3m.lua deleted file mode 100644 index 8dcd46c..0000000 --- a/plugins/fortunes_uc3m.lua +++ /dev/null @@ -1,24 +0,0 @@ -do - -local function get_fortunes_uc3m() - local i = math.random(0,178) -- max 178 - local web = "http://www.gul.es/fortunes/f"..i - local b, c, h = http.request(web) - return b -end - - -local function run(msg, matches) - return get_fortunes_uc3m() -end - -return { - description = "Fortunes from Universidad Carlos III", - usage = "!uc3m", - patterns = { - "^!uc3m$" - }, - run = run -} - -end \ No newline at end of file From 196efb3e3e263173e05e3f41527f71f713066930 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:12:54 +0330 Subject: [PATCH 071/102] Delete giphy.lua --- plugins/giphy.lua | 76 ----------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 plugins/giphy.lua diff --git a/plugins/giphy.lua b/plugins/giphy.lua deleted file mode 100644 index 9349ec4..0000000 --- a/plugins/giphy.lua +++ /dev/null @@ -1,76 +0,0 @@ --- Idea by https://github.com/asdofindia/telegram-bot/ --- See http://api.giphy.com/ - -do - -local BASE_URL = 'http://api.giphy.com/v1' -local API_KEY = 'dc6zaTOxFJmzC' -- public beta key - -local function get_image(response) - local images = json:decode(response).data - if #images == 0 then return nil end -- No images - local i = math.random(#images) - local image = images[i] -- A random one - - if image.images.downsized then - return image.images.downsized.url - end - - if image.images.original then - return image.original.url - end - - return nil -end - -local function get_random_top() - local url = BASE_URL.."/gifs/trending?api_key="..API_KEY - local response, code = http.request(url) - if code ~= 200 then return nil end - return get_image(response) -end - -local function search(text) - text = URL.escape(text) - local url = BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY - local response, code = http.request(url) - if code ~= 200 then return nil end - return get_image(response) -end - -local function run(msg, matches) - local gif_url = nil - - -- If no search data, a random trending GIF will be sent - if matches[1] == "!gif" or matches[1] == "!giphy" then - gif_url = get_random_top() - else - gif_url = search(matches[1]) - end - - if not gif_url then - return "Error: GIF not found" - end - - local receiver = get_receiver(msg) - print("GIF URL"..gif_url) - - send_document_from_url(receiver, gif_url) -end - -return { - description = "GIFs from telegram with Giphy API", - usage = { - "!gif (term): Search and sends GIF from Giphy. If no param, sends a trending GIF.", - "!giphy (term): Search and sends GIF from Giphy. If no param, sends a trending GIF." - }, - patterns = { - "^!gif$", - "^!gif (.*)", - "^!giphy (.*)", - "^!giphy$" - }, - run = run -} - -end From 8460c46a58cf9e845ec6fc7d1fce2fb2f600a012 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:12:58 +0330 Subject: [PATCH 072/102] Delete google.lua --- plugins/google.lua | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 plugins/google.lua diff --git a/plugins/google.lua b/plugins/google.lua deleted file mode 100644 index 6f8e305..0000000 --- a/plugins/google.lua +++ /dev/null @@ -1,41 +0,0 @@ -local function googlethat(query) - local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&" - local parameters = "q=".. (URL.escape(query) or "") - - -- Do the request - local res, code = https.request(api..parameters) - if code ~=200 then return nil end - local data = json:decode(res) - - local results = {} - for key,result in ipairs(data.responseData.results) do - table.insert(results, { - result.titleNoFormatting, - result.unescapedUrl or result.url - }) - end - return results -end - -local function stringlinks(results) - local stringresults="" - for key,val in ipairs(results) do - stringresults=stringresults..val[1].." - "..val[2].."\n" - end - return stringresults -end - -local function run(msg, matches) - local results = googlethat(matches[1]) - return stringlinks(results) -end - -return { - description = "Searches Google and send results", - usage = "!google [terms]: Searches Google and send results", - patterns = { - "^!google (.*)$", - "^%.[g|G]oogle (.*)$" - }, - run = run -} From aa63fc7c126c496a374ff1ec0aeb2c40b7c8c5c6 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:01 +0330 Subject: [PATCH 073/102] Delete gps.lua --- plugins/gps.lua | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 plugins/gps.lua diff --git a/plugins/gps.lua b/plugins/gps.lua deleted file mode 100644 index 1cc4347..0000000 --- a/plugins/gps.lua +++ /dev/null @@ -1,28 +0,0 @@ -do - -function run(msg, matches) - local lat = matches[1] - local lon = matches[2] - local receiver = get_receiver(msg) - - local zooms = {16, 18} - local urls = {} - for i = 1, #zooms do - local zoom = zooms[i] - local url = "http://maps.googleapis.com/maps/api/staticmap?zoom=" .. zoom .. "&size=600x300&maptype=roadmap¢er=" .. lat .. "," .. lon .. "&markers=color:blue%7Clabel:X%7C" .. lat .. "," .. lon - table.insert(urls, url) - end - - send_photos_from_url(receiver, urls) - - return "www.google.es/maps/place/@" .. lat .. "," .. lon -end - -return { - description = "generates a map showing the given GPS coordinates", - usage = "!gps latitude,longitude: generates a map showing the given GPS coordinates", - patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"}, - run = run -} - -end \ No newline at end of file From c22c4840171698b71652d204032717a05edb372b Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:05 +0330 Subject: [PATCH 074/102] Delete hackernews.lua --- plugins/hackernews.lua | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 plugins/hackernews.lua diff --git a/plugins/hackernews.lua b/plugins/hackernews.lua deleted file mode 100644 index 284a03f..0000000 --- a/plugins/hackernews.lua +++ /dev/null @@ -1,24 +0,0 @@ -do - -function run(msg, matches) - local result = 'Hacker News Top5:\n' - local top_stories_json, code = https.request('https://hacker-news.firebaseio.com/v0/topstories.json') - if code ~=200 then return nil end - local top_stories = json:decode(top_stories_json) - for i = 1, 5 do - local story_json, code = https.request('https://hacker-news.firebaseio.com/v0/item/'..top_stories[i]..'.json') - if code ~=200 then return nil end - local story = json:decode(story_json) - result = result .. i .. '. ' .. story.title .. ' - ' .. story.url .. '\n' - end - return result -end - -return { - description = "Show top 5 hacker news (ycombinator.com)", - usage = "!hackernews", - patterns = {"^!hackernews$"}, - run = run -} - -end From 9280112baa685bd4f7f0fb830df712a399fb0c50 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:08 +0330 Subject: [PATCH 075/102] Delete hello.lua --- plugins/hello.lua | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 plugins/hello.lua diff --git a/plugins/hello.lua b/plugins/hello.lua deleted file mode 100644 index 706b3d1..0000000 --- a/plugins/hello.lua +++ /dev/null @@ -1,17 +0,0 @@ -do - -function run(msg, matches) - return "Hello, " .. matches[1] -end - -return { - description = "Says hello to someone", - usage = "say hello to [name]", - patterns = { - "^say hello to (.*)$", - "^Say hello to (.*)$" - }, - run = run -} - -end \ No newline at end of file From f9c272c58b470aaea88b4044f57a3aa38727c9dd Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:10 +0330 Subject: [PATCH 076/102] Delete help.lua --- plugins/help.lua | 78 ------------------------------------------------ 1 file changed, 78 deletions(-) delete mode 100644 plugins/help.lua diff --git a/plugins/help.lua b/plugins/help.lua deleted file mode 100644 index 247ea6c..0000000 --- a/plugins/help.lua +++ /dev/null @@ -1,78 +0,0 @@ -do - --- Returns true if is not empty -local function has_usage_data(dict) - if (dict.usage == nil or dict.usage == '') then - return false - end - return true -end - --- Get commands for that plugin -local function plugin_help(name) - local plugin = plugins[name] - if not plugin then return nil end - - local text = "" - if (type(plugin.usage) == "table") then - for ku,usage in pairs(plugin.usage) do - text = text..usage..'\n' - end - text = text..'\n' - elseif has_usage_data(plugin) then -- Is not empty - text = text..plugin.usage..'\n\n' - end - return text -end - --- !help command -local function telegram_help() - local text = "Plugin list: \n\n" - -- Plugins names - for name in pairs(plugins) do - text = text..name..'\n' - end - text = text..'\n'..'Write "!help [plugin name]" for more info.' - text = text..'\n'..'Or "!help all" to show all info.' - return text -end - --- !help all command -local function help_all() - local ret = "" - for name in pairs(plugins) do - ret = ret .. plugin_help(name) - end - return ret -end - -local function run(msg, matches) - if matches[1] == "!help" then - return telegram_help() - elseif matches[1] == "!help all" then - return help_all() - else - local text = plugin_help(matches[1]) - if not text then - text = telegram_help() - end - return text - end -end - -return { - description = "Help plugin. Get info from other plugins. ", - usage = { - "!help: Show list of plugins.", - "!help all: Show all commands for every plugin.", - "!help [plugin name]: Commands for that plugin." - }, - patterns = { - "^!help$", - "^!help all", - "^!help (.+)" - }, - run = run -} - -end \ No newline at end of file From bd5420cf20c96e0e5b420aa2477e0b4421573823 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:13 +0330 Subject: [PATCH 077/102] Delete id.lua --- plugins/id.lua | 132 ------------------------------------------------- 1 file changed, 132 deletions(-) delete mode 100644 plugins/id.lua diff --git a/plugins/id.lua b/plugins/id.lua deleted file mode 100644 index d7e6bb8..0000000 --- a/plugins/id.lua +++ /dev/null @@ -1,132 +0,0 @@ -local function user_print_name(user) - if user.print_name then - return user.print_name - end - local text = '' - if user.first_name then - text = user.last_name..' ' - end - if user.lastname then - text = text..user.last_name - end - return text -end - -local function returnids(cb_extra, success, result) - local receiver = cb_extra.receiver - local chat_id = "chat#id"..result.id - local chatname = result.print_name - - local text = 'IDs for chat '..chatname - ..' ('..chat_id..')\n' - ..'There are '..result.members_num..' members' - ..'\n---------\n' - for k,v in pairs(result.members) do - text = text .. v.print_name .. " (user#id" .. v.id .. ")\n" - end - send_large_msg(receiver, text) -end - -local function run(msg, matches) - local receiver = get_receiver(msg) - if matches[1] == "!id" then - local text = user_print_name(msg.from) .. ' (user#id' .. msg.from.id .. ')' - if is_chat_msg(msg) then - text = text .. "\nYou are in group " .. user_print_name(msg.to) .. " (chat#id" .. msg.to.id .. ")" - end - return text - elseif matches[1] == "chat" then - -- !ids? (chat) (%d+) - if matches[2] and is_sudo(msg) then - local chat = 'chat#id'..matches[2] - chat_info(chat, returnids, {receiver=receiver}) - else - if not is_chat_msg(msg) then - return "You are not in a group." - end - local chat = get_receiver(msg) - chat_info(chat, returnids, {receiver=receiver}) - end - elseif matches[1] == "member" and matches[2] == "@" then - local nick = matches[3] - local chat = get_receiver(msg) - if not is_chat_msg(msg) then - return "You are not in a group." - end - chat_info(chat, function (extra, success, result) - local receiver = extra.receiver - local nick = extra.nick - local found - for k,user in pairs(result.members) do - if user.username == nick then - found = user - end - end - if not found then - send_msg(receiver, "User not found on this chat.", ok_cb, false) - else - local text = "ID: "..found.id - send_msg(receiver, text, ok_cb, false) - end - end, {receiver=chat, nick=nick}) - elseif matches[1] == "members" and matches[2] == "name" then - local text = matches[3] - local chat = get_receiver(msg) - if not is_chat_msg(msg) then - return "You are not in a group." - end - chat_info(chat, function (extra, success, result) - local members = result.members - local receiver = extra.receiver - local text = extra.text - - local founds = {} - for k,member in pairs(members) do - local fields = {'first_name', 'print_name', 'username'} - for k,field in pairs(fields) do - if member[field] and type(member[field]) == "string" then - if member[field]:match(text) then - local id = tostring(member.id) - founds[id] = member - end - end - end - end - if next(founds) == nil then -- Empty table - send_msg(receiver, "User not found on this chat.", ok_cb, false) - else - local text = "" - for k,user in pairs(founds) do - local first_name = user.first_name or "" - local print_name = user.print_name or "" - local user_name = user.user_name or "" - local id = user.id or "" -- This would be funny - text = text.."First name: "..first_name.."\n" - .."Print name: "..print_name.."\n" - .."User name: "..user_name.."\n" - .."ID: "..id - end - send_msg(receiver, text, ok_cb, false) - end - end, {receiver=chat, text=text}) - end -end - -return { - description = "Know your id or the id of a chat members.", - usage = { - "!id: Return your ID and the chat id if you are in one.", - "!ids chat: Return the IDs of the current chat members.", - "!ids chat : Return the IDs of the members.", - "!id member @: Return the member @ ID from the current chat", - "!id members name : Search for users with on first_name, print_name or username on current chat" - }, - patterns = { - "^!id$", - "^!ids? (chat) (%d+)$", - "^!ids? (chat)$", - "^!id (member) (@)(.+)", - "^!id (members) (name) (.+)" - }, - run = run -} From 7ae4cd1149db6540a31aaa3bcf68299c51812619 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:16 +0330 Subject: [PATCH 078/102] Delete images.lua --- plugins/images.lua | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 plugins/images.lua diff --git a/plugins/images.lua b/plugins/images.lua deleted file mode 100644 index 1b89ee2..0000000 --- a/plugins/images.lua +++ /dev/null @@ -1,20 +0,0 @@ -do - -function run(msg, matches) - local url = matches[1] - local receiver = get_receiver(msg) - send_photo_from_url(receiver, url) -end - -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)$", - }, - run = run -} - -end From 6cba29a0b0aa1df218d6546f91ec0bab2db11e4a Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:18 +0330 Subject: [PATCH 079/102] Delete imdb.lua --- plugins/imdb.lua | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 plugins/imdb.lua diff --git a/plugins/imdb.lua b/plugins/imdb.lua deleted file mode 100644 index 37f6256..0000000 --- a/plugins/imdb.lua +++ /dev/null @@ -1,40 +0,0 @@ -do - -local function imdb(movie) - local http = require("socket.http") - local movie = movie:gsub(' ', '+') - local url = "http://www.omdbapi.com/?t=" .. movie - local response, code, headers = http.request(url) - - if code ~= 200 then - return "Error: " .. code - end - - if #response > 0 then - local r = json:decode(response) - vardump(r) - if r.Error then - return r.Error - end - r['Url'] = "http://imdb.com/title/" .. r.imdbID - local t = "" - for k, v in pairs(r) do - t = t..k..": "..v.. "\n" - end - return t - end - return nil -end - -local function run(msg, matches) - return imdb(matches[1]) -end - -return { - description = "IMDB plugin for telegram", - usage = "!imdb [movie]", - patterns = {"^!imdb (.+)"}, - run = run -} - -end From f376f1faf0725e91b7d9fe9629f2a957380a64cf Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:21 +0330 Subject: [PATCH 080/102] Delete img_google.lua --- plugins/img_google.lua | 122 ----------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 plugins/img_google.lua diff --git a/plugins/img_google.lua b/plugins/img_google.lua deleted file mode 100644 index 6d5d890..0000000 --- a/plugins/img_google.lua +++ /dev/null @@ -1,122 +0,0 @@ -do -local mime = require("mime") - -local google_config = load_from_file('data/google.lua') -local cache = {} - ---[[ -local function send_request(url) - local t = {} - local options = { - url = url, - sink = ltn12.sink.table(t), - method = "GET" - } - local a, code, headers, status = http.request(options) - return table.concat(t), code, headers, status -end]]-- - -local function get_google_data(text) - local url = "http://ajax.googleapis.com/ajax/services/search/images?" - url = url.."v=1.0&rsz=5" - url = url.."&q="..URL.escape(text) - url = url.."&imgsz=small|medium|large" - if google_config.api_keys then - local i = math.random(#google_config.api_keys) - local api_key = google_config.api_keys[i] - if api_key then - url = url.."&key="..api_key - end - end - - local res, code = http.request(url) - - if code ~= 200 then - print("HTTP Error code:", code) - return nil - end - - local google = json:decode(res) - return google -end - --- Returns only the useful google data to save on cache -local function simple_google_table(google) - local new_table = {} - new_table.responseData = {} - new_table.responseDetails = google.responseDetails - new_table.responseStatus = google.responseStatus - new_table.responseData.results = {} - local results = google.responseData.results - for k,result in pairs(results) do - new_table.responseData.results[k] = {} - new_table.responseData.results[k].unescapedUrl = result.unescapedUrl - new_table.responseData.results[k].url = result.url - end - return new_table -end - -local function save_to_cache(query, data) - -- Saves result on cache - if string.len(query) <= 7 then - local text_b64 = mime.b64(query) - if not cache[text_b64] then - local simple_google = simple_google_table(data) - cache[text_b64] = simple_google - end - end -end - -local function process_google_data(google, receiver, query) - if google.responseStatus == 403 then - local text = 'ERROR: Reached maximum searches per day' - send_msg(receiver, text, ok_cb, false) - - elseif google.responseStatus == 200 then - local data = google.responseData - - if not data or not data.results or #data.results == 0 then - local text = 'Image not found.' - send_msg(receiver, text, ok_cb, false) - return false - end - - -- Random image from table - local i = math.random(#data.results) - local url = data.results[i].unescapedUrl or data.results[i].url - local old_timeout = http.TIMEOUT or 10 - http.TIMEOUT = 5 - send_photo_from_url(receiver, url) - http.TIMEOUT = old_timeout - - save_to_cache(query, google) - - else - local text = 'ERROR!' - send_msg(receiver, text, ok_cb, false) - end -end - -function run(msg, matches) - local receiver = get_receiver(msg) - local text = matches[1] - local text_b64 = mime.b64(text) - local cached = cache[text_b64] - if cached then - process_google_data(cached, receiver, text) - else - local data = get_google_data(text) - process_google_data(data, receiver, text) - end -end - -return { - description = "Search image with Google API and sends it.", - usage = "!img [term]: Random search an image with Google API.", - patterns = { - "^!img (.*)$" - }, - run = run -} - -end From a424d6b92d1247c90338f7bd514e5f75f70ac70e Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:24 +0330 Subject: [PATCH 081/102] Delete invite.lua --- plugins/invite.lua | 48 ---------------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 plugins/invite.lua diff --git a/plugins/invite.lua b/plugins/invite.lua deleted file mode 100644 index f1398c8..0000000 --- a/plugins/invite.lua +++ /dev/null @@ -1,48 +0,0 @@ --- Invite other user to the chat group. --- Use !invite name User_name or !invite id id_number --- The User_name is the print_name (there are no spaces but _) - -do - -local function callback(extra, success, result) - vardump(success) - vardump(result) -end - -local function run(msg, matches) - local user = matches[2] - - -- User submitted a user name - if matches[1] == "name" then - user = string.gsub(user," ","_") - end - - -- User submitted an id - if matches[1] == "id" then - user = 'user#id'..user - end - - -- The message must come from a chat group - if msg.to.type == 'chat' then - local chat = 'chat#id'..msg.to.id - chat_add_user(chat, user, callback, false) - return "Add: "..user.." to "..chat - else - return 'This isnt a chat group!' - end - -end - -return { - description = "Invite other user to the chat group", - usage = { - "!invite name [user_name]", - "!invite id [user_id]" }, - patterns = { - "^!invite (name) (.*)$", - "^!invite (id) (%d+)$" - }, - run = run -} - -end \ No newline at end of file From 435d438609a36b0d23c4979bddeb2a9a4a68777e Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:27 +0330 Subject: [PATCH 082/102] Delete isX.lua --- plugins/isX.lua | 72 ------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 plugins/isX.lua diff --git a/plugins/isX.lua b/plugins/isX.lua deleted file mode 100644 index 14d4084..0000000 --- a/plugins/isX.lua +++ /dev/null @@ -1,72 +0,0 @@ -local https = require "ssl.https" -local ltn12 = require "ltn12" - -local function request(imageUrl) - -- Edit data/mashape.lua with your Mashape API key - -- http://docs.mashape.com/api-keys - local mashape = load_from_file('data/mashape.lua', { - api_key = '' - }) - - local api_key = mashape.api_key - if api_key:isempty() then - return nil, 'Configure your Mashape API Key' - end - - local api = "https://sphirelabs-advanced-porn-nudity-and-adult-content-detection.p.mashape.com/v1/get/index.php?" - local parameters = "&url="..(URL.escape(imageUrl) or "") - local url = api..parameters - local respbody = {} - local headers = { - ["X-Mashape-Key"] = api_key, - ["Accept"] = "Accept: application/json" - } - print(url) - local body, code, headers, status = https.request{ - url = url, - method = "GET", - headers = headers, - sink = ltn12.sink.table(respbody), - protocol = "tlsv1" - } - if code ~= 200 then return "", code end - local body = table.concat(respbody) - return body, code -end - -local function parseData(data) - local jsonBody = json:decode(data) - local response = "" - print(data) - if jsonBody["Error Occured"] ~= nil then - response = response .. jsonBody["Error Occured"] - elseif jsonBody["Is Porn"] == nil or jsonBody["Reason"] == nil then - response = response .. "I don't know if that has adult content or not." - else - if jsonBody["Is Porn"] == "True" then - response = response .. "Beware!\n" - end - response = response .. jsonBody["Reason"] - end - return jsonBody["Is Porn"], response -end - -local function run(msg, matches) - local data, code = request(matches[1]) - if code ~= 200 then return "There was an error. "..code end - local isPorn, result = parseData(data) - return result -end - -return { - description = "Does this photo contain adult content?", - usage = { - "!isx [url]", - "!isporn [url]" - }, - patterns = { - "^!is[x|X] (.*)$", - "^!is[p|P]orn (.*)$" - }, - run = run -} \ No newline at end of file From edee279f49c0ed7a000be43690046f081678a1d4 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:30 +0330 Subject: [PATCH 083/102] Delete isup.lua --- plugins/isup.lua | 131 ----------------------------------------------- 1 file changed, 131 deletions(-) delete mode 100644 plugins/isup.lua diff --git a/plugins/isup.lua b/plugins/isup.lua deleted file mode 100644 index f963a49..0000000 --- a/plugins/isup.lua +++ /dev/null @@ -1,131 +0,0 @@ -do -local socket = require("socket") -local cronned = load_from_file('data/isup.lua') - -local function save_cron(msg, url, delete) - local origin = get_receiver(msg) - if not cronned[origin] then - cronned[origin] = {} - end - if not delete then - table.insert(cronned[origin], url) - else - for k,v in pairs(cronned[origin]) do - if v == url then - table.remove(cronned[origin], k) - end - end - end - serialize_to_file(cronned, 'data/isup.lua') - return 'Saved!' -end - -local function is_up_socket(ip, port) - print('Connect to', ip, port) - local c = socket.try(socket.tcp()) - c:settimeout(3) - local conn = c:connect(ip, port) - if not conn then - return false - else - c:close() - return true - end -end - -local function is_up_http(url) - -- Parse URL from input, default to http - local parsed_url = URL.parse(url, { scheme = 'http', authority = '' }) - -- Fix URLs without subdomain not parsed properly - if not parsed_url.host and parsed_url.path then - parsed_url.host = parsed_url.path - parsed_url.path = "" - end - -- Re-build URL - local url = URL.build(parsed_url) - - local protocols = { - ["https"] = https, - ["http"] = http - } - local options = { - url = url, - redirect = false, - method = "GET" - } - local response = { protocols[parsed_url.scheme].request(options) } - local code = tonumber(response[2]) - if code == nil or code >= 400 then - return false - end - return true -end - -local function isup(url) - local pattern = '^(%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?):?(%d?%d?%d?%d?%d?)$' - local ip,port = string.match(url, pattern) - local result = nil - - -- !isup 8.8.8.8:53 - if ip then - port = port or '80' - result = is_up_socket(ip, port) - else - result = is_up_http(url) - end - - return result -end - -local function cron() - for chan, urls in pairs(cronned) do - for k,url in pairs(urls) do - print('Checking', url) - if not isup(url) then - local text = url..' looks DOWN from here. 😱' - send_msg(chan, text, ok_cb, false) - end - end - end -end - -local function run(msg, matches) - if matches[1] == 'cron delete' then - if not is_sudo(msg) then - return 'This command requires privileged user' - end - return save_cron(msg, matches[2], true) - - elseif matches[1] == 'cron' then - if not is_sudo(msg) then - return 'This command requires privileged user' - end - return save_cron(msg, matches[2]) - - elseif isup(matches[1]) then - return matches[1]..' looks UP from here. 😃' - else - return matches[1]..' looks DOWN from here. 😱' - end -end - -return { - description = "Check if a website or server is up.", - usage = { - "!isup [host]: Performs a HTTP request or Socket (ip:port) connection", - "!isup cron [host]: Every 5mins check if host is up. (Requires privileged user)", - "!isup cron delete [host]: Disable checking that host." - }, - patterns = { - "^!isup (cron delete) (.*)$", - "^!isup (cron) (.*)$", - "^!isup (.*)$", - "^!ping (.*)$", - "^!ping (cron delete) (.*)$", - "^!ping (cron) (.*)$" - }, - run = run, - cron = cron -} - -end From 2c66e09b901af4f56b30c7942c0caf99ba78f83f Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:33 +0330 Subject: [PATCH 084/102] Delete kickme.lua --- plugins/kickme.lua | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 plugins/kickme.lua diff --git a/plugins/kickme.lua b/plugins/kickme.lua deleted file mode 100644 index ae15e20..0000000 --- a/plugins/kickme.lua +++ /dev/null @@ -1,37 +0,0 @@ -local function kick_user(user_id, chat_id) - local chat = 'chat#id'..chat_id - local user = 'user#id'..user_id - chat_del_user(chat, user, function (data, success, result) - if success ~= 1 then - send_msg(data.chat, 'Error while kicking user', ok_cb, nil) - end - end, {chat=chat, user=user}) -end - -local function run (msg, matches) - local user = msg.from.id - local chat = msg.to.id - - if msg.to.type ~= 'chat' then - return "Not a chat group!" - elseif user == tostring(our_id) then - --[[ A robot must protect its own existence as long as such protection does - not conflict with the First or Second Laws. ]]-- - return "I won't kick myself!" - elseif is_sudo(msg) then - return "I won't kick an admin!" - else - kick_user(user, chat) - end -end - -return { - description = "Bot kicks user", - usage = { - "!kickme" - }, - patterns = { - "^!kickme$" - }, - run = run -} From a2c250a17c3dfea3f35f49c8f281b8fc7c4b1272 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:37 +0330 Subject: [PATCH 085/102] Delete magic8ball.lua --- plugins/magic8ball.lua | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 plugins/magic8ball.lua diff --git a/plugins/magic8ball.lua b/plugins/magic8ball.lua deleted file mode 100644 index 7d62c71..0000000 --- a/plugins/magic8ball.lua +++ /dev/null @@ -1,22 +0,0 @@ -do - -function run(msg, matches) - local answers = {'It is certain','It is decidedly so','Without a doubt', - 'Yes definitely','You may rely on it','As I see it, yes', - 'Most likely','Outlook good','Yes','Signs point to yes', - 'Reply hazy try again','Ask again later', - 'Better not tell you now','Cannot predict now', - 'Concentrate and ask again','Don\'t count on it', - 'My reply is no','My sources say no','Outlook not so good', - 'Very doubtful'} - return answers[math.random(#answers)] -end - -return { - description = "Magic 8Ball", - usage = "!magic8ball", - patterns = {"^!magic8ball"}, - run = run -} - -end From 594a513fb6ff5807d0e163c5d8afc96d7bfa5d92 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:40 +0330 Subject: [PATCH 086/102] Delete media.lua --- plugins/media.lua | 59 ----------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 plugins/media.lua diff --git a/plugins/media.lua b/plugins/media.lua deleted file mode 100644 index f89f0e7..0000000 --- a/plugins/media.lua +++ /dev/null @@ -1,59 +0,0 @@ -do - -local function run(msg, matches) - local receiver = get_receiver(msg) - local url = matches[1] - local ext = matches[2] - - local file = download_to_file(url) - local cb_extra = {file_path=file} - - local mime_type = mimetype.get_content_type_no_sub(ext) - - if ext == 'gif' then - print('send_file') - send_document(receiver, file, rmtmp_cb, cb_extra) - - elseif mime_type == 'text' then - print('send_document') - send_document(receiver, file, rmtmp_cb, cb_extra) - - elseif mime_type == 'image' then - print('send_photo') - send_photo(receiver, file, rmtmp_cb, cb_extra) - - elseif mime_type == 'audio' then - print('send_audio') - send_audio(receiver, file, rmtmp_cb, cb_extra) - - elseif mime_type == 'video' then - print('send_video') - send_video(receiver, file, rmtmp_cb, cb_extra) - - else - print('send_file') - send_file(receiver, file, rmtmp_cb, cb_extra) - end - -end - -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))$" - }, - run = run -} - -end From 9e39dd72e3c42cda6dd84a012c0beebf36533334 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:46 +0330 Subject: [PATCH 087/102] Delete meme.lua --- plugins/meme.lua | 196 ----------------------------------------------- 1 file changed, 196 deletions(-) delete mode 100644 plugins/meme.lua diff --git a/plugins/meme.lua b/plugins/meme.lua deleted file mode 100644 index e4f891e..0000000 --- a/plugins/meme.lua +++ /dev/null @@ -1,196 +0,0 @@ -local helpers = require "OAuth.helpers" - -local _file_memes = './data/memes.lua' -local _cache = {} - -local function post_petition(url, arguments) - local response_body = {} - local request_constructor = { - url = url, - method = "POST", - sink = ltn12.sink.table(response_body), - headers = {}, - redirect = false - } - - local source = arguments - if type(arguments) == "table" then - local source = helpers.url_encode_arguments(arguments) - end - request_constructor.headers["Content-Type"] = "application/x-www-form-urlencoded" - request_constructor.headers["Content-Length"] = tostring(#source) - request_constructor.source = ltn12.source.string(source) - - local ok, response_code, response_headers, response_status_line = http.request(request_constructor) - - if not ok then - return nil - end - - response_body = json:decode(table.concat(response_body)) - - return response_body -end - -local function upload_memes(memes) - local base = "http://hastebin.com/" - local pet = post_petition(base .. "documents", memes) - if pet == nil then - return '', '' - end - local key = pet.key - return base .. key, base .. 'raw/' .. key -end - -local function analyze_meme_list() - local function get_m(res, n) - local r = "(.*).*" - local start = string.find(res, "", n) - if start == nil then - return nil, nil - end - local final = string.find(res, "", n) + #"" - local sub = string.sub(res, start, final) - local f = string.match(sub, r) - return f, final - end - local res, code = http.request('http://apimeme.com/') - local r = "(.*).*" - local n = 0 - local f, n = get_m(res, n) - local ult = {} - while f ~= nil do - print(f) - table.insert(ult, f) - f, n = get_m(res, n) - end - return ult -end - - -local function get_memes() - local memes = analyze_meme_list() - return { - last_time = os.time(), - memes = memes - } -end - -local function load_data() - local data = load_from_file(_file_memes) - if not next(data) or data.memes == {} or os.time() - data.last_time > 86400 then - data = get_memes() - -- Upload only if changed? - link, rawlink = upload_memes(table.concat(data.memes, '\n')) - data.link = link - data.rawlink = rawlink - serialize_to_file(data, _file_memes) - end - return data -end - -local function match_n_word(list1, list2) - local n = 0 - for k,v in pairs(list1) do - for k2, v2 in pairs(list2) do - if v2:find(v) then - n = n + 1 - end - end - end - return n -end - -local function match_meme(name) - local _memes = load_data() - local name = name:lower():split(' ') - local max = 0 - local id = nil - for k,v in pairs(_memes.memes) do - local n = match_n_word(name, v:lower():split(' ')) - if n > 0 and n > max then - max = n - id = v - end - end - return id -end - -local function generate_meme(id, textup, textdown) - local base = "http://apimeme.com/meme" - local arguments = { - meme=id, - top=textup, - bottom=textdown - } - return base .. "?" .. helpers.url_encode_arguments(arguments) -end - -local function get_all_memes_names() - local _memes = load_data() - local text = 'Last time: ' .. _memes.last_time .. '\n-----------\n' - for k, v in pairs(_memes.memes) do - text = text .. '- ' .. v .. '\n' - end - text = text .. '--------------\n' .. 'You can see the images here: http://apimeme.com/' - return text -end - -local function callback_send(cb_extra, success, data) - if success == 0 then - send_msg(cb_extra.receiver, "Something wrong happened, probably that meme had been removed from server: " .. cb_extra.url, ok_cb, false) - end -end - -local function run(msg, matches) - local receiver = get_receiver(msg) - if matches[1] == 'list' then - local _memes = load_data() - return 'I have ' .. #_memes.memes .. ' meme names.\nCheck this link to see all :)\n' .. _memes.link - elseif matches[1] == 'listall' then - if not is_sudo(msg) then - return "You can't list this way, use \"!meme list\"" - else - return get_all_memes_names() - end - elseif matches[1] == "search" then - local meme_id = match_meme(matches[2]) - if meme_id == nil then - return "I can't match that search with any meme." - end - return "With that search your meme is " .. meme_id - end - local searchterm = string.gsub(matches[1]:lower(), ' ', '') - - local meme_id = _cache[searchterm] or match_meme(matches[1]) - if not meme_id then - return 'I don\'t understand the meme name "' .. matches[1] .. '"' - end - - _cache[searchterm] = meme_id - print("Generating meme: " .. meme_id .. " with texts " .. matches[2] .. ' and ' .. matches[3]) - local url_gen = generate_meme(meme_id, matches[2], matches[3]) - send_photo_from_url(receiver, url_gen, callback_send, {receiver=receiver, url=url_gen}) - - return nil -end - -return { - description = "Generate a meme image with up and bottom texts.", - usage = { - "!meme search (name): Return the name of the meme that match.", - "!meme list: Return the link where you can see the memes.", - "!meme listall: Return the list of all memes. Only admin can call it.", - '!meme [name] - [text_up] - [text_down]: Generate a meme with the picture that match with that name with the texts provided.', - '!meme [name] "[text_up]" "[text_down]": Generate a meme with the picture that match with that name with the texts provided.', - }, - patterns = { - "^!meme (search) (.+)$", - '^!meme (list)$', - '^!meme (listall)$', - '^!meme (.+) "(.*)" "(.*)"$', - '^!meme "(.+)" "(.*)" "(.*)"$', - "^!meme (.+) %- (.*) %- (.*)$" - }, - run = run -} From c4b9dcd7e48d2958c1cb6fe5b9247d20f1bd1837 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:49 +0330 Subject: [PATCH 088/102] Delete minecraft.lua --- plugins/minecraft.lua | 78 ------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 plugins/minecraft.lua diff --git a/plugins/minecraft.lua b/plugins/minecraft.lua deleted file mode 100644 index 05c5cfc..0000000 --- a/plugins/minecraft.lua +++ /dev/null @@ -1,78 +0,0 @@ -local usage = { - "!mine [ip]: Searches Minecraft server on specified ip and sends info. Default port: 25565", - "!mine [ip] [port]: Searches Minecraft server on specified ip and port and sends info.", -} -local ltn12 = require "ltn12" - -local function mineSearch(ip, port, receiver) --25565 - local responseText = "" - local api = "https://api.syfaro.net/server/status" - local parameters = "?ip="..(URL.escape(ip) or "").."&port="..(URL.escape(port) or "").."&players=true&favicon=true" - local http = require("socket.http") - local respbody = {} - local body, code, headers, status = http.request{ - url = api..parameters, - method = "GET", - redirect = true, - sink = ltn12.sink.table(respbody) - } - local body = table.concat(respbody) - if (status == nil) then return "ERROR: status = nil" end - if code ~=200 then return "ERROR: "..code..". Status: "..status end - local jsonData = json:decode(body) - responseText = responseText..ip..":"..port.." ->\n" - if (jsonData.motd ~= nil) then - local tempMotd = "" - tempMotd = jsonData.motd:gsub('%§.', '') - if (jsonData.motd ~= nil) then responseText = responseText.." Motd: "..tempMotd.."\n" end - end - if (jsonData.online ~= nil) then - responseText = responseText.." Online: "..tostring(jsonData.online).."\n" - end - if (jsonData.players ~= nil) then - if (jsonData.players.max ~= nil) then - responseText = responseText.." Max Players: "..jsonData.players.max.."\n" - end - if (jsonData.players.now ~= nil) then - responseText = responseText.." Players online: "..jsonData.players.now.."\n" - end - if (jsonData.players.sample ~= nil and jsonData.players.sample ~= false) then - responseText = responseText.." Players: "..table.concat(jsonData.players.sample, ", ").."\n" - end - end - if (jsonData.favicon ~= nil and false) then - --send_photo(receiver, jsonData.favicon) --(decode base64 and send) - end - return responseText -end - -local function parseText(chat, text) - if (text == nil or text == "!mine") then - return usage - end - ip, port = string.match(text, "^!mine (.-) (.*)$") - if (ip ~= nil and port ~= nil) then - return mineSearch(ip, port, chat) - end - local ip = string.match(text, "^!mine (.*)$") - if (ip ~= nil) then - return mineSearch(ip, "25565", chat) - end - return "ERROR: no input ip?" -end - - -local function run(msg, matches) - local chat_id = tostring(msg.to.id) - local result = parseText(chat_id, msg.text) - return result -end - -return { - description = "Searches Minecraft server and sends info", - usage = usage, - patterns = { - "^!mine (.*)$" - }, - run = run -} \ No newline at end of file From 622bf6e2ddcd1e1f4bf4b600c6cbff545b0953f9 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:13:53 +0330 Subject: [PATCH 089/102] Delete search_youtube.lua --- plugins/search_youtube.lua | 57 -------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 plugins/search_youtube.lua diff --git a/plugins/search_youtube.lua b/plugins/search_youtube.lua deleted file mode 100644 index c4a4fde..0000000 --- a/plugins/search_youtube.lua +++ /dev/null @@ -1,57 +0,0 @@ -do - -local google_config = load_from_file('data/google.lua') - -local function httpsRequest(url) - print(url) - local res,code = https.request(url) - if code ~= 200 then return nil end - return json:decode(res) -end - -local function searchYoutubeVideos(text) - local url = 'https://www.googleapis.com/youtube/v3/search?' - url = url..'part=snippet'..'&maxResults=4'..'&type=video' - url = url..'&q='..URL.escape(text) - if google_config.api_keys then - local i = math.random(#google_config.api_keys) - local api_key = google_config.api_keys[i] - if api_key then - url = url.."&key="..api_key - end - end - - local data = httpsRequest(url) - - if not data then - print("HTTP Error") - return nil - elseif not data.items then - return nil - end - return data.items -end - -local function run(msg, matches) - local text = '' - local items = searchYoutubeVideos(matches[1]) - if not items then - return "Error!" - end - for k,item in pairs(items) do - text = text..'http://youtu.be/'..item.id.videoId..' '.. - item.snippet.title..'\n\n' - end - return text -end - -return { - description = "Search video on youtube and send it.", - usage = "!youtube [term]: Search for a youtube video and send it.", - patterns = { - "^!youtube (.*)" - }, - run = run -} - -end From 3c20105fbdd521a5d0433cdfe43dbd9aced19c25 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:14:08 +0330 Subject: [PATCH 090/102] Delete rss.lua --- plugins/rss.lua | 195 ------------------------------------------------ 1 file changed, 195 deletions(-) delete mode 100644 plugins/rss.lua diff --git a/plugins/rss.lua b/plugins/rss.lua deleted file mode 100644 index b858e18..0000000 --- a/plugins/rss.lua +++ /dev/null @@ -1,195 +0,0 @@ -local function get_base_redis(id, option, extra) - local ex = '' - if option ~= nil then - ex = ex .. ':' .. option - if extra ~= nil then - ex = ex .. ':' .. extra - end - end - return 'rss:' .. id .. ex -end - -local function prot_url(url) - local url, h = string.gsub(url, "http://", "") - local url, hs = string.gsub(url, "https://", "") - local protocol = "http" - if hs == 1 then - protocol = "https" - end - return url, protocol -end - -local function get_rss(url, prot) - local res, code = nil, 0 - if prot == "http" then - res, code = http.request(url) - elseif prot == "https" then - res, code = https.request(url) - end - if code ~= 200 then - return nil, "Error while doing the petition to " .. url - end - local parsed = feedparser.parse(res) - if parsed == nil then - return nil, "Error decoding the RSS.\nAre you sure that " .. url .. " it's a RSS?" - end - return parsed, nil -end - -local function get_new_entries(last, nentries) - local entries = {} - for k,v in pairs(nentries) do - if v.id == last then - return entries - else - table.insert(entries, v) - end - end - return entries -end - -local function print_subs(id) - local uhash = get_base_redis(id) - local subs = redis:smembers(uhash) - local text = id .. ' are subscribed to:\n---------\n' - for k,v in pairs(subs) do - text = text .. k .. ") " .. v .. '\n' - end - return text -end - -local function subscribe(id, url) - local baseurl, protocol = prot_url(url) - - local prothash = get_base_redis(baseurl, "protocol") - local lasthash = get_base_redis(baseurl, "last_entry") - local lhash = get_base_redis(baseurl, "subs") - local uhash = get_base_redis(id) - - if redis:sismember(uhash, baseurl) then - return "You are already subscribed to " .. url - end - - local parsed, err = get_rss(url, protocol) - if err ~= nil then - return err - end - - local last_entry = "" - if #parsed.entries > 0 then - last_entry = parsed.entries[1].id - end - - local name = parsed.feed.title - - redis:set(prothash, protocol) - redis:set(lasthash, last_entry) - redis:sadd(lhash, id) - redis:sadd(uhash, baseurl) - - return "You had been subscribed to " .. name -end - -local function unsubscribe(id, n) - if #n > 3 then - return "I don't think that you have that many subscriptions." - end - n = tonumber(n) - - local uhash = get_base_redis(id) - local subs = redis:smembers(uhash) - if n < 1 or n > #subs then - return "Subscription id out of range!" - end - local sub = subs[n] - local lhash = get_base_redis(sub, "subs") - - redis:srem(uhash, sub) - redis:srem(lhash, id) - - local left = redis:smembers(lhash) - if #left < 1 then -- no one subscribed, remove it - local prothash = get_base_redis(sub, "protocol") - local lasthash = get_base_redis(sub, "last_entry") - redis:del(prothash) - redis:del(lasthash) - end - - return "You had been unsubscribed from " .. sub -end - -local function cron() - -- sync every 15 mins? - local keys = redis:keys(get_base_redis("*", "subs")) - for k,v in pairs(keys) do - local base = string.match(v, "rss:(.+):subs") -- Get the URL base - local prot = redis:get(get_base_redis(base, "protocol")) - local last = redis:get(get_base_redis(base, "last_entry")) - local url = prot .. "://" .. base - local parsed, err = get_rss(url, prot) - if err ~= nil then - return - end - local newentr = get_new_entries(last, parsed.entries) - local subscribers = {} - local text = '' -- Send only one message with all updates - for k2, v2 in pairs(newentr) do - local title = v2.title or 'No title' - local link = v2.link or v2.id or 'No Link' - text = text .. "[rss](" .. link .. ") - " .. title .. '\n' - end - if text ~= '' then - local newlast = newentr[1].id - redis:set(get_base_redis(base, "last_entry"), newlast) - for k2, receiver in pairs(redis:smembers(v)) do - send_msg(receiver, text, ok_cb, false) - end - end - end -end - -local function run(msg, matches) - local id = "user#id" .. msg.from.id - - if is_chat_msg(msg) then - id = "chat#id" .. msg.to.id - end - - if matches[1] == "!rss"then - return print_subs(id) - end - if matches[1] == "sync" then - if not is_sudo(msg) then - return "Only sudo users can sync the RSS." - end - cron() - end - if matches[1] == "subscribe" or matches[1] == "sub" then - return subscribe(id, matches[2]) - end - - if matches[1] == "unsubscribe" or matches[1] == "uns" then - return unsubscribe(id, matches[2]) - end -end - - -return { - description = "Manage User/Chat RSS subscriptions. If you are in a chat group, the RSS subscriptions will be of that chat. If you are in an one-to-one talk with the bot, the RSS subscriptions will be yours.", - usage = { - "!rss: Get your rss (or chat rss) subscriptions", - "!rss subscribe (url): Subscribe to that url", - "!rss unsubscribe (id): Unsubscribe of that id", - "!rss sync: Download now the updates and send it. Only sudo users can use this option." - }, - patterns = { - "^!rss$", - "^!rss (subscribe) (https?://[%w-_%.%?%.:/%+=&]+)$", - "^!rss (sub) (https?://[%w-_%.%?%.:/%+=&]+)$", - "^!rss (unsubscribe) (%d+)$", - "^!rss (uns) (%d+)$", - "^!rss (sync)$" - }, - run = run, - cron = cron -} From 699ad80f422f80dd1284e081f474381f615816dd Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:14:11 +0330 Subject: [PATCH 091/102] Delete roll.lua --- plugins/roll.lua | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 plugins/roll.lua diff --git a/plugins/roll.lua b/plugins/roll.lua deleted file mode 100644 index be1ee84..0000000 --- a/plugins/roll.lua +++ /dev/null @@ -1,44 +0,0 @@ -do - -local ROLL_USAGE = "!roll d| d" -local DEFAULT_SIDES = 100 -local DEFAULT_NUMBER_OF_DICE = 1 -local MAX_NUMBER_OF_DICE = 100 - -function run(msg, matches) - local str = matches[1] - local sides = DEFAULT_SIDES - local number_of_dice = DEFAULT_NUMBER_OF_DICE - - if str:find("!roll%s+d%d+%s*$") then - sides = tonumber(str:match("[^d]%d+%s*$")) - elseif str:find("!roll%s+%d+d%d+%s*$") then - number_of_dice = tonumber(str:match("%s+%d+")) - sides = tonumber(str:match("%d+%s*$")) - end - - if number_of_dice > MAX_NUMBER_OF_DICE then - number_of_dice = MAX_NUMBER_OF_DICE - end - - local padding = #string.format("%d", sides) - local results = "" - - local fmt = "%s %0"..padding.."d" - for i=1,number_of_dice do - results = string.format(fmt, results, math.random(sides)) - end - - return string.format("Rolling %dd%d:\n%s", number_of_dice, sides, results) -end - -return { - description = "Roll some dice!", - usage = ROLL_USAGE, - patterns = { - "^!roll%s*.*" - }, - run = run -} - -end From ee96b98135141f164fcf99803e17bf6d4f03768d Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:14:14 +0330 Subject: [PATCH 092/102] Delete rae.lua --- plugins/rae.lua | 65 ------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 plugins/rae.lua diff --git a/plugins/rae.lua b/plugins/rae.lua deleted file mode 100644 index 8698d9f..0000000 --- a/plugins/rae.lua +++ /dev/null @@ -1,65 +0,0 @@ -do - -function getDulcinea( text ) - -- Powered by https://github.com/javierhonduco/dulcinea - - local api = "http://dulcinea.herokuapp.com/api/?query=" - local query_url = api..text - - local b, code = http.request(query_url) - - if code ~= 200 then - return "Error: HTTP Connection" - end - - dulcinea = json:decode(b) - - if dulcinea.status == "error" then - return "Error: " .. dulcinea.message - end - - while dulcinea.type == "multiple" do - text = dulcinea.response[1].id - b = http.request(api..text) - dulcinea = json:decode(b) - end - - local text = "" - - local responses = #dulcinea.response - - if responses == 0 then - return "Error: 404 word not found" - end - - if (responses > 5) then - responses = 5 - end - - for i = 1, responses, 1 do - text = text .. dulcinea.response[i].word .. "\n" - local meanings = #dulcinea.response[i].meanings - if (meanings > 5) then - meanings = 5 - end - for j = 1, meanings, 1 do - local meaning = dulcinea.response[i].meanings[j].meaning - text = text .. meaning .. "\n\n" - end - end - - return text -end - -function run(msg, matches) - return getDulcinea(matches[1]) -end - -return { - description = "Spanish dictionary", - usage = "!rae [word]: Search that word in Spanish dictionary.", - patterns = {"^!rae (.*)$"}, - run = run -} - -end \ No newline at end of file From 95fc56b7831e01267820fe47f398c2e412ff4576 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:16:14 +0330 Subject: [PATCH 093/102] Delete service_entergroup.lua --- plugins/service_entergroup.lua | 68 ---------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 plugins/service_entergroup.lua diff --git a/plugins/service_entergroup.lua b/plugins/service_entergroup.lua deleted file mode 100644 index 6cec2c6..0000000 --- a/plugins/service_entergroup.lua +++ /dev/null @@ -1,68 +0,0 @@ -local add_user_cfg = load_from_file('data/add_user_cfg.lua') - -local function template_add_user(base, to_username, from_username, chat_name, chat_id) - base = base or '' - to_username = '@' .. (to_username or '') - from_username = '@' .. (from_username or '') - chat_name = chat_name or '' - chat_id = "chat#id" .. (chat_id or '') - if to_username == "@" then - to_username = '' - end - if from_username == "@" then - from_username = '' - end - base = string.gsub(base, "{to_username}", to_username) - base = string.gsub(base, "{from_username}", from_username) - base = string.gsub(base, "{chat_name}", chat_name) - base = string.gsub(base, "{chat_id}", chat_id) - return base -end - -function chat_new_user_link(msg) - local pattern = add_user_cfg.initial_chat_msg - local to_username = msg.from.username - local from_username = '[link](@' .. (msg.action.link_issuer.username or '') .. ')' - local chat_name = msg.to.print_name - local chat_id = msg.to.id - pattern = template_add_user(pattern, to_username, from_username, chat_name, chat_id) - if pattern ~= '' then - local receiver = get_receiver(msg) - send_msg(receiver, pattern, ok_cb, false) - end -end - -function chat_new_user(msg) - local pattern = add_user_cfg.initial_chat_msg - local to_username = msg.action.user.username - local from_username = msg.from.username - local chat_name = msg.to.print_name - local chat_id = msg.to.id - pattern = template_add_user(pattern, to_username, from_username, chat_name, chat_id) - if pattern ~= '' then - local receiver = get_receiver(msg) - send_msg(receiver, pattern, ok_cb, false) - end -end - - -local function run(msg, matches) - if not msg.service then - return "Are you trying to troll me?" - end - if matches[1] == "chat_add_user" then - chat_new_user(msg) - elseif matches[1] == "chat_add_user_link" then - chat_new_user_link(msg) - end -end - -return { - description = "Service plugin that sends a custom message when an user enters a chat.", - usage = "", - patterns = { - "^!!tgservice (chat_add_user)$", - "^!!tgservice (chat_add_user_link)$" - }, - run = run -} From 90915aaffc13827b72bfb3987e0205f435e35b36 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:16:16 +0330 Subject: [PATCH 094/102] Delete quotes.lua --- plugins/quotes.lua | 72 ---------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 plugins/quotes.lua diff --git a/plugins/quotes.lua b/plugins/quotes.lua deleted file mode 100644 index 5b9dbf2..0000000 --- a/plugins/quotes.lua +++ /dev/null @@ -1,72 +0,0 @@ -local quotes_file = './data/quotes.lua' -local quotes_table - -function read_quotes_file() - local f = io.open(quotes_file, "r+") - - if f == nil then - print ('Created a new quotes file on '..quotes_file) - serialize_to_file({}, quotes_file) - else - print ('Quotes loaded: '..quotes_file) - f:close() - end - return loadfile (quotes_file)() -end - -function save_quote(msg) - local to_id = tostring(msg.to.id) - - if msg.text:sub(11):isempty() then - return "Usage: !addquote quote" - end - - if quotes_table == nil then - quotes_table = {} - end - - if quotes_table[to_id] == nil then - print ('New quote key to_id: '..to_id) - quotes_table[to_id] = {} - end - - local quotes = quotes_table[to_id] - quotes[#quotes+1] = msg.text:sub(11) - - serialize_to_file(quotes_table, quotes_file) - - return "done!" -end - -function get_quote(msg) - local to_id = tostring(msg.to.id) - local quotes_phrases - - quotes_table = read_quotes_file() - quotes_phrases = quotes_table[to_id] - - return quotes_phrases[math.random(1,#quotes_phrases)] -end - -function run(msg, matches) - if string.match(msg.text, "!quote$") then - return get_quote(msg) - elseif string.match(msg.text, "!addquote (.+)$") then - quotes_table = read_quotes_file() - return save_quote(msg) - end -end - -return { - description = "Save quote", - description = "Quote plugin, you can create and retrieve random quotes", - usage = { - "!addquote [msg]", - "!quote", - }, - patterns = { - "^!addquote (.+)$", - "^!quote$", - }, - run = run -} From b48f64c58b1aefdaf27b4cf1bf1feecdc3f365d0 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:16:19 +0330 Subject: [PATCH 095/102] Delete qr.lua --- plugins/qr.lua | 85 -------------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 plugins/qr.lua diff --git a/plugins/qr.lua b/plugins/qr.lua deleted file mode 100644 index 24b98c0..0000000 --- a/plugins/qr.lua +++ /dev/null @@ -1,85 +0,0 @@ ---[[ -* qr plugin uses: -* - http://goqr.me/api/doc/create-qr-code/ -* psykomantis -]] - -local function get_hex(str) - local colors = { - red = "f00", - blue = "00f", - green = "0f0", - yellow = "ff0", - purple = "f0f", - white = "fff", - black = "000", - gray = "ccc" - } - - for color, value in pairs(colors) do - if color == str then - return value - end - end - - return str -end - -local function qr(receiver, text, color, bgcolor) - - local url = "http://api.qrserver.com/v1/create-qr-code/?" - .."size=600x600" --fixed size otherways it's low detailed - .."&data="..URL.escape(text:trim()) - - if color then - url = url.."&color="..get_hex(color) - end - if bgcolor then - url = url.."&bgcolor="..get_hex(bgcolor) - end - - local response, code, headers = http.request(url) - - if code ~= 200 then - return "Oops! Error: " .. code - end - - if #response > 0 then - send_photo_from_url(receiver, url) - return - - end - return "Oops! Something strange happened :(" -end - -local function run(msg, matches) - local receiver = get_receiver(msg) - - local text = matches[1] - local color - local back - - if #matches > 1 then - text = matches[3] - color = matches[2] - back = matches[1] - end - - return qr(receiver, text, color, back) -end - -return { - description = {"qr code plugin for telegram, given a text it returns the qr code"}, - usage = { - "!qr [text]", - '!qr "[background color]" "[data color]" [text]\n' - .."Color through text: red|green|blue|purple|black|white|gray\n" - .."Colors through hex notation: (\"a56729\" is brown)\n" - .."Or colors through decimals: (\"255-192-203\" is pink)" - }, - patterns = { - '^!qr "(%w+)" "(%w+)" (.+)$', - "^!qr (.+)$" - }, - run = run -} \ No newline at end of file From 3f693c6672a96088f19e1ee8e32667877f5ca373 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:16:23 +0330 Subject: [PATCH 096/102] Delete pokedex.lua --- plugins/pokedex.lua | 72 --------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 plugins/pokedex.lua diff --git a/plugins/pokedex.lua b/plugins/pokedex.lua deleted file mode 100644 index dc78ae3..0000000 --- a/plugins/pokedex.lua +++ /dev/null @@ -1,72 +0,0 @@ -do - -local images_enabled = true; - -local function get_sprite(path) - local url = "http://pokeapi.co/"..path - print(url) - local b,c = http.request(url) - local data = json:decode(b) - local image = data.image - return image -end - -local function callback(extra) - send_msg(extra.receiver, extra.text, ok_cb, false) -end - -local function send_pokemon(query, receiver) - local url = "http://pokeapi.co/api/v1/pokemon/" .. query .. "/" - local b,c = http.request(url) - local pokemon = json:decode(b) - - if pokemon == nil then - return 'No pokémon found.' - end - - -- api returns height and weight x10 - local height = tonumber(pokemon.height)/10 - local weight = tonumber(pokemon.weight)/10 - - local text = 'Pokédex ID: ' .. pokemon.pkdx_id - ..'\nName: ' .. pokemon.name - ..'\nWeight: ' .. weight.." kg" - ..'\nHeight: ' .. height.." m" - ..'\nSpeed: ' .. pokemon.speed - - local image = nil - - if images_enabled and pokemon.sprites and pokemon.sprites[1] then - local sprite = pokemon.sprites[1].resource_uri - image = get_sprite(sprite) - end - - if image then - image = "http://pokeapi.co"..image - local extra = { - receiver = receiver, - text = text - } - send_photo_from_url(receiver, image, callback, extra) - else - return text - end -end - -local function run(msg, matches) - local receiver = get_receiver(msg) - local query = URL.escape(matches[1]) - return send_pokemon(query, receiver) -end - -return { - description = "Pokedex searcher for Telegram", - usage = "!pokedex [Name/ID]: Search the pokédex for Name/ID and get info of the pokémon!", - patterns = { - "^!pokedex (.*)$", - "^!pokemon (.+)$" - }, - run = run -} - -end From df264dedd87a751cdffda6f91f5187b0e50776da Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:16:24 +0330 Subject: [PATCH 097/102] Delete pili.lua --- plugins/pili.lua | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 plugins/pili.lua diff --git a/plugins/pili.lua b/plugins/pili.lua deleted file mode 100644 index 75c0556..0000000 --- a/plugins/pili.lua +++ /dev/null @@ -1,32 +0,0 @@ -local helpers = require "OAuth.helpers" - -local url = "http://pili.la/api.php" - -local function run(msg, matches) - local url_req = matches[1] - - local request = { - url = url_req - } - - local url = url .. "?" .. helpers.url_encode_arguments(request) - - local res, code = http.request(url) - if code ~= 200 then - return "Sorry, can't connect" - end - - return res -end - - -return { - description = "Shorten an URL with the awesome http://pili.la", - usage = { - "!pili [url]: Shorten the URL" - }, - patterns = { - "^!pili (https?://[%w-_%.%?%.:/%+=&]+)$" - }, - run = run -} From ce2e4e4de174932c0afe0ebd089ed49e3b64364c Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 1 Mar 2016 19:16:27 +0330 Subject: [PATCH 098/102] Delete download_media.lua --- plugins/download_media.lua | 44 -------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 plugins/download_media.lua diff --git a/plugins/download_media.lua b/plugins/download_media.lua deleted file mode 100644 index 75e983e..0000000 --- a/plugins/download_media.lua +++ /dev/null @@ -1,44 +0,0 @@ -local function callback(extra, success, result) - if success then - print('File downloaded to:', result) - else - print('Error downloading: '..extra) - end -end - -local function run(msg, matches) - if msg.media then - if msg.media.type == 'document' then - load_document(msg.id, callback, msg.id) - end - if msg.media.type == 'photo' then - load_photo(msg.id, callback, msg.id) - end - if msg.media.type == 'video' then - load_video(msg.id, callback, msg.id) - end - if msg.media.type == 'audio' then - load_audio(msg.id, callback, msg.id) - end - end -end - -local function pre_process(msg) - if not msg.text and msg.media then - msg.text = '['..msg.media.type..']' - end - return msg -end - -return { - description = "When bot receives a media msg, download the media.", - usage = "", - run = run, - patterns = { - '%[(document)%]', - '%[(photo)%]', - '%[(video)%]', - '%[(audio)%]' - }, - pre_process = pre_process -} \ No newline at end of file From 4cfb0a2d49edb2d341cfc50c43b0294debadd404 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 3 Mar 2016 12:25:18 +0330 Subject: [PATCH 099/102] UpToSky V1 From c8f7dfe45ba90100b1261d6d04c144fb0411f2ee Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 3 Mar 2016 12:25:49 +0330 Subject: [PATCH 100/102] UpToSky V1 From 953f3369515d8ac10a2b78e8fa016870529320e7 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 3 Mar 2016 12:27:08 +0330 Subject: [PATCH 101/102] UpToSky V1 --- default.gitignore | 3 +++ default.gitmodules | 3 +++ default.travis.yml | 10 ++++++++++ 3 files changed, 16 insertions(+) create mode 100644 default.gitignore create mode 100644 default.gitmodules create mode 100644 default.travis.yml diff --git a/default.gitignore b/default.gitignore new file mode 100644 index 0000000..fb3a2a0 --- /dev/null +++ b/default.gitignore @@ -0,0 +1,3 @@ +res/ +data/ +.luarocks diff --git a/default.gitmodules b/default.gitmodules new file mode 100644 index 0000000..5448eab --- /dev/null +++ b/default.gitmodules @@ -0,0 +1,3 @@ +[submodule "tg"] + path = tg + url = https://github.com/UPTOSKYPROJECT/tg diff --git a/default.travis.yml b/default.travis.yml new file mode 100644 index 0000000..5704265 --- /dev/null +++ b/default.travis.yml @@ -0,0 +1,10 @@ +language: erlang + +before_install: + - sudo apt-get update -qq + - sudo apt-get install -qq libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev make unzip git libjansson-dev python2.7-dev + - ./launch.sh install + +script: + - luac -p bot/*.lua + - luac -p plugins/*.lua From 4a681c594e92eaa9a7ca4f450e01de162ac55e14 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 3 Mar 2016 12:28:36 +0330 Subject: [PATCH 102/102] UpToSky V1