async def mqtt_test(msg: Message, *args): if bot.user_ignored(str(msg.author)): return # Build the message message = "" for arg in args: message += f"{arg} " if await bot.MQTT.send(MqttTopics.test, message): await msg.reply(f"{bot.msg_prefix} Connection successful.") else: await msg.reply(f"{bot.msg_prefix} Connection error.")
async def topic(self, msg, *args): # Check if user is on ignore list if bot.user_ignored(str(msg.author)): return topic = get_topic() if not msg.is_whisper: await msg.reply(f"{bot.msg_prefix}{topic}") else: try: # Send message directly to channel 0 await channels[cfg.channels[0]].send_message(topic) except Exception as e: print(e)
async def on_raw_message(self, msg: Message) -> None: """Increment the user message counter""" # Make sure the user actually sent a message,and it's not a whisper. if not msg.is_user_message or msg.is_whisper: return if msg.author not in self.seen_users: if not bot.user_ignored(msg.author): await bot.MQTT.send( new_chatter_topic, dumps({ "author": msg.author, "timestamp": str(datetime.now()) })) print(f"New chatter {msg.author} sent to MQTT.") # Track that we've seen the user self.seen_users.add(msg.author)
async def push_treat(self, msg: Message, *args): if perms.has_permission(msg.channel.name, str(msg.author), "admin"): if self.points.check(msg, mod_commands=1): await self.send_treat(msg) elif msg.args[0] == "test": # Use for testing the bots await self.send_treat_in_queue(msg) await sleep(3) await self.send_treat(msg) else: status = self.points.status() await msg.reply(self.build_required_message(status)) else: # Check if user is on ignore list if bot.user_ignored(str(msg.author)): return await msg.reply( f"{bot.msg_prefix} NEW! Send balden3TreatMe to trigger the Treat Bot!" ) # TODO #136 Change phrasing eventually
async def on_raw_message(self, msg: Message) -> None: """Increment the user message counter""" # Make sure the user actually sent a message,and it's not a whisper. if not msg.is_user_message or msg.is_whisper: return user_id = msg.tags.user_id server_id = msg.tags.room_id rows_affected = (session.query(Users).filter( Users.user_id == user_id, Users.channel == server_id).update({ "message_count": Users.message_count + 1, "last_message": datetime.now() })) # If the user doesn't exist, insert them if not rows_affected: user_object = Users(user_id=user_id, channel=server_id, user=msg.author, message_count=1) session.add(user_object) # Added for #155 # If we have had a raid in the last 60 seconds, don't send anything for the new users, # even thought they got inserted into the database. if (self.last_raid + timedelta(seconds=60)) < datetime.now(): if not bot.user_ignored(msg.author): await bot.MQTT.send( first_time_chatter_topic, dumps({ "author": msg.author, "timestamp": str(datetime.now()) })) print(f"New user {msg.author} sent to MQTT.") session.commit()
async def lost(self, msg: Message, *args): # Check if user is on ignore list if bot.user_ignored(str(msg.author)): return # Increase both counts self.lost_count["session"] += 1 self.lost_count["total"] += 1 rows_affected = (session.query(Settings).filter( Settings.key == "lost_count").update( {"value": json.dumps(self.lost_count)})) if not rows_affected: ins = Settings(key="lost_count", value=json.dumps(self.lost_count)) session.add(ins) session.commit() await msg.reply( f"@baldengineer has lost {self.lost_count['session']} things so far today, {self.lost_count['total']} total." )