diff --git a/README.md b/README.md index bc5c2f6..ace222d 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,15 @@ Command | Parameter(s) | Description `/ping` | N/A | Return current session information `/poem` | N/A | Read poetry (TBD) +### Placeholder + +Bot is now support placeholder, using them in welcome message, +bot will auto-replace them to what you wish + +Placeholder | Replace to +---|---- +`$name` | new user first name + ### Flags detail Flag | Description | Default status @@ -24,13 +33,13 @@ noblue | While bot is admin, it will delete bot command after 5 seconds (need de ### Example -Set welcome message to **Welcome to my group**: +Set welcome message to **Welcome [who] to my group**: ``` -/setwelcome **Welcome to my group** +/setwelcome **Welcome $name to my group** ``` or ``` -/setwelcome https://gist.githubusercontent.com/anonymous/a196757970b0358db6e69f4cc8413ce5/raw/1a548bf3c2d1c7d38cd1fde70c6a612b5d58f524/welcomemsg +/setwelcome https://gist.githubusercontent.com/anonymous/6446fbae52916bc7fb092dd1ee3f8483/raw/4ad5231d5e2a68458e117db9bed97407dfe6f47b/welcomemsg ``` _After you run this command, bot will reply your a message_ diff --git a/botlib/groupcache.py b/botlib/groupcache.py index 4e6ba04..a65e530 100644 --- a/botlib/groupcache.py +++ b/botlib/groupcache.py @@ -41,6 +41,7 @@ def add(self,x,need_check_admin=True,not_found=False): if not not_found: self.__db_del(x[0]) Log.info('Delete kicked chat:{}',x[0]) + return except telepot.exception.TelegramError as e: if e[0] == 'Bad Request: chat not found': if not not_found: @@ -52,6 +53,8 @@ def add(self,x,need_check_admin=True,not_found=False): Log.error('Delete kicked chat:{}', x[0]) else: raise e + finally: + result = 0 else: result = 0 self.g[x[0]]={'msg' : x[1], diff --git a/botlib/tgbot.py b/botlib/tgbot.py index 19b3bd4..fab6e71 100644 --- a/botlib/tgbot.py +++ b/botlib/tgbot.py @@ -88,6 +88,7 @@ def onMessage(self,msg): Log.debug(3,'Incoming message') content_type, chat_type, chat_id = self.glance(msg) Log.debug(3, '[msg = {}]', msg) + # Added process if content_type == 'new_chat_member' and msg['new_chat_participant']['id'] == self.getid(): self.gcache.add((chat_id,None,0,1,0)) with MainDatabase() as db: @@ -102,13 +103,15 @@ def onMessage(self,msg): self.sendMessage(chat_id,'Please using /setwelcome to setting welcome message', reply_to_message_id=msg['message_id']) return + # kicked process if content_type == 'left_chat_member' and msg['left_chat_member']['id'] == self.getid(): self.gcache.delete(chat_id) return + # Main process if msg['chat']['type'] in group_type: if content_type == 'text' and 'entities' in msg and msg[ - 'entities'][0]['type'] == 'bot_command': #msg['text'][0] =='/': - + 'entities'][0]['type'] == 'bot_command' and msg[ + 'text'][0] == '/': # Prevent suchas './sudo' get_result = self.gcache.get(chat_id) if get_result['noblue']: delete_target_message(self.bot,chat_id,msg['message_id']).start() @@ -201,5 +204,5 @@ def onMessage(self,msg): elif content_type in content_type_concerned: result = self.gcache.get(chat_id)['msg'] if result: - self.sendMessage(chat_id,b64decode(result),parse_mode='Markdown', - disable_web_page_preview=True,reply_to_message_id=msg['message_id']) + self.sendMessage(chat_id,b64decode(result).replace('$name',msg['new_chat_participant']['first_name']), + parse_mode='Markdown',disable_web_page_preview=True,reply_to_message_id=msg['message_id']) diff --git a/libpy b/libpy index 51ddf67..56d9e30 160000 --- a/libpy +++ b/libpy @@ -1 +1 @@ -Subproject commit 51ddf67e3b2b6cc2ea3b85e5b145f63764220afe +Subproject commit 56d9e308888e4f1de4eda4eafe1a72a17ce7193d diff --git a/main.py b/main.py index a180853..5b722db 100644 --- a/main.py +++ b/main.py @@ -13,11 +13,10 @@ import libpy.BackupSQL as BackupSQL def main(): - global bot,group_cache,poem_cache Log.info('Strat initializing....') Log.info('Debug enable: {}',Log.get_debug_info()[0]) Log.debug(1,'Debug level: {}',Log.get_debug_info()[1]) - bot = bot_class() + bot_class() Log.info('Bot is now running!') Log.info('Starting BackupSQL daemon') BackupSQL.sql_backup_daemon().start()