welcome/bye on join/leave group

function to alter msg before checking against plugin triggers
This commit is contained in:
dupie 2015-07-10 03:52:22 -04:00
parent 947d397673
commit 8c9a5ae7ba
4 changed files with 31 additions and 3 deletions

View File

@ -6,6 +6,9 @@ Public bot runs on [@mokubot](http://telegram.me/mokubot).
Requires lua-socket and lua-sec. [dkjson](https://github.com/LuaDist/dkjson/) is provided.
Edit config.json with your bot API key, and other API keys if desirable.
Plugins which require an API key are disabled by default.
`lua bot.lua`
###Configuration

22
bot.lua
View File

@ -3,13 +3,15 @@
HTTP = require('socket.http')
HTTPS = require('ssl.https')
JSON = require('dkjson')
URL = require('socket.url')
JSON = require('dkjson')
VERSION = 2.2
VERSION = 2.3
function on_msg_receive(msg)
msg = process_msg(msg)
if msg.date < os.time() - 5 then return end -- don't react to old messages
if not msg.text then return end -- don't react to media messages
if msg.forward_from then return end -- don't react to forwarded messages
@ -72,6 +74,22 @@ function bot_init()
end
function process_msg(msg)
if msg.new_chat_participant and msg.new_chat_participant.id ~= bot.id then
msg.text = 'hi '..bot.first_name
msg.from = msg.new_chat_participant
end
if msg.left_chat_participant and msg.left_chat_participant.id ~= bot.id then
msg.text = 'bye '..bot.first_name
msg.from = msg.left_chat_participant
end
return msg
end
bot_init()
reminders = {}
last_update = 0

View File

@ -1,4 +1,4 @@
-- shout-out to @luksi_reiku for showing me this site
-- shout-out to @luksireiku for showing me this site
local PLUGIN = {}

View File

@ -32,6 +32,10 @@ function PLUGIN.action(msg) -- I WISH LUA HAD PROPER REGEX SUPPORT
return send_message(msg.chat.id, 'Hi, ' .. msg.from.first_name .. '!')
end
if input:match('bye,? '..bot.first_name) or input:match('later,? '..bot.first_name) then
return send_message(msg.chat.id, 'Bye-bye, ' .. msg.from.first_name .. '!')
end
if input:match('i hate you,? '..bot.first_name) or input:match('screw you,? '..bot.first_name) or input:match('fuck you,? '..bot.first_name) then
return send_msg(msg, '; _ ;')
end
@ -40,6 +44,9 @@ function PLUGIN.action(msg) -- I WISH LUA HAD PROPER REGEX SUPPORT
return send_msg(msg, '<3')
end
-- msg.text = '@' .. bot.username .. ', ' .. msg.text:gsub(bot.first_name, '')
-- on_msg_receive(msg)
end
return PLUGIN