From 8c9a5ae7ba3a2afb541908f5a8b935ff499c1c33 Mon Sep 17 00:00:00 2001 From: dupie Date: Fri, 10 Jul 2015 03:52:22 -0400 Subject: [PATCH] welcome/bye on join/leave group function to alter msg before checking against plugin triggers --- README.md | 3 +++ bot.lua | 22 ++++++++++++++++++++-- plugins/chatter.lua | 2 +- plugins/personality.lua | 7 +++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 62114f7..2762c1b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bot.lua b/bot.lua index adadfce..7516057 100644 --- a/bot.lua +++ b/bot.lua @@ -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 diff --git a/plugins/chatter.lua b/plugins/chatter.lua index 0189f98..952f71c 100644 --- a/plugins/chatter.lua +++ b/plugins/chatter.lua @@ -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 = {} diff --git a/plugins/personality.lua b/plugins/personality.lua index 70b3056..ad6f448 100644 --- a/plugins/personality.lua +++ b/plugins/personality.lua @@ -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