def handle_message(bot, update): message_text = update.message.text if is_keyword_mentioned(message_text): logger.info("Replied to message of user '{}' in chat '{}'".format(update.message.from_user.id, update.message.chat.id)) bot.send_message(chat_id=update.message.chat_id, text=get_random_quote(), reply_to_message_id=update.message.message_id, parse_mode=ParseMode.MARKDOWN)
async def on_message(message): # Do not reply to comments from these users, including itself (client.user) blocked_users = [client.user] # Bot does not reply to itself and only when mentioned if is_keyword_mentioned(message.content): #logger.info("Replied to message of user '{}' in guild '{}' / channel '{}'".format(message.author, message.guild, message.channel)) msg = get_random_quote().format(message) await message.channel.send(msg)
async def on_message(message): # Do not reply to comments from these users, including itself (client.user) blocked_users = [client.user] # Bot does not reply to itself and only when mentioned if is_keyword_mentioned( message.content) and message.author not in blocked_users: #logger.info("Replied to message of user '{}' in guild '{}' / channel '{}'".format(message.author, message.guild, message.channel)) msg = get_random_quote().format(message) await message.channel.send(msg) elif message.author not in blocked_users and message.content.lower( ).startswith('trigger rg'): await message.channel.send( "Trigger me with words: pappu, rahul gandhi, raul vinci, rahul")
async def on_message(message): # If running in test environment, do not reply to any calls if environment == 'TEST': return # Do not reply to comments from these users, including itself (client.user) blocked_users = [client.user] # Bot does not reply to itself and only when mentioned if client.user.mentioned_in( message) and message.author not in blocked_users: logger.info( "Replied to message of user '{}' in server '{}' / channel '{}'". format(message.author, message.server, message.channel)) msg = get_random_quote().format(message) await client.send_message(message.channel, msg)
# Get the replies from the subreddits subreddit = reddit.subreddit(subreddits) for comment in subreddit.stream.comments(): # Check if author name exists or not username = get_username(comment.author) # If we haven't replied to this comment before and the comment author is not blocked if comment.id not in posts_replied_to and username not in users_list: if is_keyword_mentioned(comment.body): # Reply to the post and write activity to the log comment.reply(get_random_quote()) logger.info( "Replied to comment in subreddit '{}'".format( comment.subreddit)) # Store the current id into our list posts_replied_to.append(comment.id) logger.info("Appended replied posts to list") # Write our updated list back to the posts_replied_to.txt file and to the log with open("posts_replied_to.txt", "a") as f: f.write(comment.id + "\n") logger.info( "Written to 'posts_replied_to.txt' file, ID '{}'". format(comment.id))