async def on_message(self, message: Message): # allow irc users to use commands by altering content to remove the nick before sending for command processing # note that clean_content is *not* altered and everything relies on this fact for it to work without having to go back and lookup the message in the db # if message.content.startswith("**<"): # <-- FOR TESTING if user_is_irc_bot(message): # Search for first "> " and strip the message from there (Since irc nicks cant have <, > in them idx = message.content.find(">** ") idx += 4 message.content = message.content[idx:] await self.bot.process_commands(message)
async def add(self, ctx: Context, *args: clean_content): if not args: await ctx.send("You're missing a time and a message!") else: trigger_time = parse_time(args[0]) now = datetime.now() if not trigger_time: await ctx.send("Incorrect time format, please see help text.") elif trigger_time < now: await ctx.send("That time is in the past.") else: # HURRAY the time is valid and not in the past, add the reminder display_name = get_name_string(ctx.message) # set the id to a random value if the author was the bridge bot, since we wont be using it anyways # if ctx.message.clean_content.startswith("**<"): <---- FOR TESTING if user_is_irc_bot(ctx): author_id = 1 irc_n = display_name else: author_id = ( db_session.query(User) .filter(User.user_uid == ctx.author.id) .first() .id ) irc_n = None if len(args) > 1: rem_content = " ".join(args[1:]) trig_at = trigger_time trig = False playback_ch_id = ctx.message.channel.id new_reminder = Reminder( user_id=author_id, reminder_content=rem_content, trigger_at=trig_at, triggered=trig, playback_channel_id=playback_ch_id, irc_name=irc_n, ) db_session.add(new_reminder) try: db_session.commit() await ctx.send( f"Thanks {display_name}, I have saved your reminder (but please note that my granularity is set at {CONFIG.REMINDER_SEARCH_INTERVAL} seconds)." ) except (ScalarListException, SQLAlchemyError) as e: db_session.rollback() logging.error(e) await ctx.send(f"Something went wrong") else: await ctx.send("Please include some reminder text!")
async def on_message(self, message: Message): # If the message is by a bot that's not irc then ignore it if message.author.bot and not user_is_irc_bot(message): return user = (db_session.query(User).filter( User.user_uid == message.author.id).one_or_none()) if not user: user = User(user_uid=message.author.id, username=str(message.author)) db_session.add(user) else: user.last_seen = message.created_at # Commit the session so the user is available now try: db_session.commit() except (ScalarListException, SQLAlchemyError) as e: db_session.rollback() logging.error(e) # Something very wrong, but not way to reliably recover so abort return # Only log messages that were in a public channel if isinstance(message.channel, GuildChannel): # Log the message to the database logged_message = LoggedMessage( message_uid=message.id, message_content=message.clean_content, author=user.id, created_at=message.created_at, channel_name=message.channel.name, ) db_session.add(logged_message) try: db_session.commit() except (ScalarListException, SQLAlchemyError) as e: db_session.rollback() logging.error(e) return # KARMA # Get all specified command prefixes for the bot command_prefixes = self.bot.command_prefix(self.bot, message) # Only process karma if the message was not a command (ie did not start with a command prefix) if not any( message.content.startswith(prefix) for prefix in command_prefixes): reply = process_karma(message, logged_message.id, db_session, CONFIG.KARMA_TIMEOUT) if reply: await message.channel.send(reply)
def is_self_karma(karma_item: KarmaItem, message: Message) -> bool: topic = karma_item.topic.casefold() if user_is_irc_bot(message): username = message.clean_content.split(" ")[0][3:-3].casefold() return username == topic else: username = message.author.name.casefold() if username == topic: return True if message.author.nick is None: return False else: return message.author.nick.casefold() == topic
async def fact(self, ctx: Context): display_name = get_name_string(ctx.message) if json := self.get_online_fact(): if user_is_irc_bot(ctx): await ctx.send( f"{display_name}: {json['text']} (from <{json['source']}>)" ) else: embed = Embed( title=json["text"], description=f'[{json["source"]}]({json["source"]})', colour=Colour.random(), ).set_footer(text=json["index"]) await ctx.send(embed=embed)