async def update_rank_piflex_master(bot): """ Changes the rank of the players with the most discovered piflex images -- input: bot: interactions.Client """ guild = Guild(id=Constants.GUILD_IDS[0], _client=bot._http) role = Role(id=Constants.PIFLEX_MASTER_ROLE_ID) L = sorted(list(db["discovered_piflex"].items()), key=lambda key_val: -len(key_val[1])) # in case of ties L = list(filter(lambda key_val: len(key_val[1]) == len(L[0][1]), L)) user_ids = [key_val[0] for key_val in L] # Remove old piflex masters for user_id in db["current_piflex_masters"]: if user_id not in user_ids: member = await guild.get_member(int(user_id)) await member.remove_role(role, guild_id=guild.id) # Setup new piflex masters for user_id, amount in L: if user_id not in db["current_piflex_masters"]: user = await guild.get_member(int(user_id)) await user.add_role(role, guild_id=guild.id) db["current_piflex_masters"] = user_ids
async def update_rank_pilord(bot): """ Changes the rank of the players with the most piflouz -- input: bot: interactions.Client """ if "piflouz_bank" not in db.keys(): return guild = Guild(id=Constants.GUILD_IDS[0], _client=bot._http) role = Role(id=Constants.PILORD_ROLE_ID) L = sorted(list(db["piflouz_bank"].items()), key=lambda key_val: -int(key_val[1])) # in case of ties L = list(filter(lambda key_val: key_val[1] == L[0][1], L)) user_ids = [key_val[0] for key_val in L] # Remove old pilords for user_id in db["current_pilords"]: if user_id not in user_ids: member = await guild.get_member(int(user_id)) await member.remove_role(role, guild_id=guild.id) # Setup new pilords for user_id, amount in L: if user_id not in db["current_pilords"]: member = await guild.get_member(int(user_id)) await member.add_role(role, guild_id=guild.id) bot.dispatch("become_pilord", user_id) db["current_pilords"] = user_ids
async def spawn_pibox(bot, piflouz_quantity, custom_message=None): """ Generates a pibox of the amount passed in argument. -- input: bot: interactions.Client amount: int, positive custom_message: either None, or a custom message (str) to add at the end. """ out_channel = await bot.get_channel(db["out_channel"]) index = randrange(len(Constants.EMOJI_IDS_FOR_PIBOX)) emoji_id = Constants.EMOJI_IDS_FOR_PIBOX[index] emoji_name = Constants.EMOJI_NAMES_FOR_PIBOX[index] emoji = f"<:{emoji_name}:{emoji_id}>" role = Role(id=Constants.PIBOX_NOTIF_ROLE_ID) text_output = f"{role.mention} Be Fast ! First to react with {emoji} will get {piflouz_quantity} {Constants.PIFLOUZ_EMOJI} !" if custom_message is not None: text_output += " " + custom_message message = await out_channel.send(text_output) db["random_gifts"][str( message.id)] = [emoji_id, piflouz_quantity, custom_message]
async def update_rank_mega_piflexer(bot): """ Removes the mega-piflexer roles when they need to be -- input: bot: interactions.Client """ if "mega_piflexers" not in db.keys(): return t = time.time() guild = Guild(id=Constants.GUILD_IDS[0], _client=bot._http) role = Role(id=Constants.MEGA_PIFLEXER_ROLE_ID) for id, old_time in db["mega_piflexers"].items(): if t - old_time >= Constants.MEGA_PIFLEXER_ROLE_DURATION: member = await guild.get_member(int(id)) await member.remove_role(role, guild_id=guild.id) del db["mega_piflexers"][id]
async def actions_every_5min(self, bot): if "out_channel" not in db.keys(): return out_channel = await bot.get_channel(db["out_channel"]) # Amount of each ingredient qty = [random.randint(1, 5) for _ in self.ingredients] # Disable previous deliveries delivery = db["last_birthday_delivery"] db["last_birthday_delivery"] = dict() if delivery != dict(): msg = await out_channel.get_message(delivery["id"]) components = components = [ self.get_component(emoji, nb, disabled=True) for emoji, nb in zip(self.ingredients, delivery["qty"].values()) ] await msg.edit("Unfortunately, the delivery person has left", components=components) # Check if a delivery happens if random.random() > self.spawn_rate: return # Create a new delivery components = [ self.get_component(emoji, nb) for emoji, nb in zip(self.ingredients, qty) ] role_notif = Role(id=Constants.BIRTHDAY_NOTIF_ROLE_ID) msg = await out_channel.send( f"{role_notif.mention} A new cake ingredient delivery has appeared! But you can only take one type so chose carefully", components=components) db["last_birthday_delivery"] = { "id": int(msg.id), "qty": {e: nb for e, nb in zip(self.ingredients, qty)} }
async def send_new_live_message(bot, stream, streamer_name): """ Sends a message saying a streamer is now live -- input: bot: interactions.Client stream: twitch.helix.Stream streamer_name: str -> the name of the streamer who went live """ current_live_message_time = int(time.time()) if ( current_live_message_time - db["previous_live_message_time"][streamer_name] ) >= Constants.TWITCH_ANNOUNCEMENT_DELAY: #Checks if we waited long enough db["previous_live_message_time"][ streamer_name] = current_live_message_time out_channel = await bot.get_channel(db["twitch_channel"]) role = Role(id=Constants.TWITCH_NOTIF_ROLE_ID) msg = escape_markdown( f"{role.mention} {streamer_name} is currently live on \"{stream.title}\", go check out on https://www.twitch.tv/{streamer_name} ! {Constants.FUEGO_EMOJI}" ) await out_channel.send(msg) else: print(f"Found {streamer_name}, but cooldown was still up.")