async def test_remove_user_from_ta(twitch_alert_db_manager_tables): test_add_user_to_ta_default_message(twitch_alert_db_manager_tables) await twitch_alert_db_manager_tables.remove_user_from_ta( 1234567891, "monstercat") sql_find_twitch_alert = select(UserInTwitchAlert.twitch_username, UserInTwitchAlert.custom_message)\ .where(and_(UserInTwitchAlert.channel_id == 1234567891, UserInTwitchAlert.twitch_username == 'monstercat')) with session_manager() as session: assert session.execute(sql_find_twitch_alert).one_or_none() is None
async def test_get_emails(): with session_manager() as session: test_verified_email = VerifiedEmails(u_id=123, email=TEST_EMAIL) session.add(test_verified_email) session.commit() await dpytest.message(koalabot.COMMAND_PREFIX + "getEmails 123") assert dpytest.verify().message().content(f"""This user has registered with:\n{TEST_EMAIL}""") session.delete(test_verified_email) session.commit()
def get_all_ignored(self, guild_id): with session_manager() as session: rows = session.execute(select(TextFilterIgnoreList.ignore_id, TextFilterIgnoreList.guild_id, TextFilterIgnoreList.ignore_type, TextFilterIgnoreList.ignore) .filter_by(guild_id=guild_id, ignore_type="channel")).all() rows += session.execute(select(TextFilterIgnoreList.ignore_id, TextFilterIgnoreList.guild_id, TextFilterIgnoreList.ignore_type, TextFilterIgnoreList.ignore) .filter_by(guild_id=guild_id, ignore_type="user")).all() return rows
def get_teams_in_ta(self, channel_id): """ Returns all teams in a given Twitch Alert :param channel_id: The channel ID of the Twitch Alert :return: The sql results of the teams """ sql_get_teams = select(TeamInTwitchAlert.twitch_team_name).filter_by(channel_id=channel_id) with session_manager() as session: return session.execute(sql_get_teams).all()
def get_filtered_text_for_guild(self, guild_id): """ Retrieves all filtered words for a specific guild and formats into a nice list of words :param guild_id: Guild ID to retrieve filtered words from: :return: list of filtered words """ with session_manager() as session: rows = session.execute(select(TextFilter).filter_by(guild_id=guild_id)).scalars() return [(row.filtered_text, row.filter_type, str(int(row.is_regex))) for row in rows]
def remove_guild_rfr_required_role(self, guild_id: int, role_id: int): """ Removes a role from the list of roles required to use rfr functionality in a guild :param guild_id: guild ID :param role_id: role ID :return: """ with session_manager() as session: session.execute(delete(GuildRFRRequiredRoles).filter_by(guild_id=guild_id, role_id=role_id)) session.commit()
def add_guild_rfr_required_role(self, guild_id: int, role_id: int): """ Adds a role to the list of roles required to use rfr functionality in a guild. :param guild_id: guild ID :param role_id: role ID :return: """ with session_manager() as session: session.add(GuildRFRRequiredRoles(guild_id=guild_id, role_id=role_id)) session.commit()
async def add_fake_guild_to_db(id=-1): with session_manager() as session: if id == 9999: return -1 if id == -1: id = dpyfactory.make_id() intro_db.remove_guild_welcome_message(id) session.add(GuildWelcomeMessages(guild_id=id, welcome_message='fake guild welcome message')) session.commit() return id
def twitch_alert_db_manager_tables(twitch_alert_db_manager): with session_manager() as session: session.execute(delete(TwitchAlerts)) session.execute(delete(TeamInTwitchAlert)) session.execute(delete(UserInTwitchAlert)) session.execute(delete(UserInTwitchTeam)) session.commit() setup() return twitch_alert_db_manager
def test_new_ta(twitch_alert_db_manager_tables): assert utils.DEFAULT_MESSAGE == twitch_alert_db_manager_tables.new_ta( guild_id=1234, channel_id=2345) sql_check_db_updated = select(TwitchAlerts.guild_id, TwitchAlerts.default_message)\ .where(TwitchAlerts.channel_id == 2345) with session_manager() as session: result: TwitchAlerts = session.execute(sql_check_db_updated).fetchone() assert result.guild_id == 1234 assert result.default_message == utils.DEFAULT_MESSAGE
def does_word_exist(self, ft_id): """ Checks if word exists in database given an ID :param ft_id: filtered text id of word to be removed :return boolean of whether the word exists or not: """ with session_manager() as session: return len(session.execute(select(TextFilter) .filter_by(filtered_text_id=ft_id)).all()) > 0
async def test_remove_team_from_ta(twitch_alert_db_manager_tables): test_add_team_to_ta_custom_message(twitch_alert_db_manager_tables, channel_id=590, guild_id=591) await twitch_alert_db_manager_tables.remove_team_from_ta(590, "faze") sql_select_team = select(TeamInTwitchAlert.custom_message)\ .where(and_(TeamInTwitchAlert.channel_id == 590, TeamInTwitchAlert.twitch_team_name == 'faze')) with session_manager() as session: assert session.execute(sql_select_team).one_or_none() is None
def test_votemanager_generate_opt_id(): with session_manager() as session: session.add( VoteOptions(vote_id=123, opt_id=100000000000000001, option_title="test", option_desc="option")) session.commit() opt_id = vote_manager.generate_unique_opt_id() assert opt_id != 100000000000000001
async def test_verify(): with session_manager() as session: test_config = dpytest.get_config() guild = test_config.guilds[0] member = guild.members[0] dm = await member.create_dm() await dpytest.message(koalabot.COMMAND_PREFIX + f"verify {TEST_EMAIL}", dm) assert dpytest.verify().message().content("Please verify yourself using the command you have been emailed") entry = session.execute(select(NonVerifiedEmails).filter_by(u_id=member.id, email=TEST_EMAIL)).all() assert entry
def update_all_teams_members(self): """ Updates all teams with the current team members :return: """ with session_manager() as session: teams_info = session.execute(select(TeamInTwitchAlert)).scalars().all() for team_info in teams_info: self.update_team_members(team_info.team_twitch_alert_id, team_info.twitch_team_name)
def does_ignore_exist(self, ignore_id): """ Checks if ignore exists in database given an ID :param ignore_id: ignore id of ignore to be removed :return boolean of whether the ignore exists or not: """ with session_manager() as session: return len(session.execute(select(TextFilterIgnoreList) .filter_by(ignore_id=ignore_id)).all()) > 0
async def test_filter_risky_word(tf_cog): with session_manager() as session: await dpytest.message(koalabot.COMMAND_PREFIX + "filter_word yup risky") assert_filtered_confirmation("yup", "risky") await dpytest.message("yup test") assert_risky_warning("yup test") cleanup(dpytest.get_config().guilds[0].id, tf_cog, session)
def test_new_ta_message(twitch_alert_db_manager_tables): test_message = "Test message" assert test_message == twitch_alert_db_manager_tables.new_ta( guild_id=1234, channel_id=23456, default_message=test_message) sql_check_db_updated = select(TwitchAlerts.guild_id, TwitchAlerts.default_message)\ .where(TwitchAlerts.channel_id == 23456) with session_manager() as session: result: TwitchAlerts = session.execute(sql_check_db_updated).fetchone() assert result.guild_id == 1234 assert result.default_message == test_message
def set_end_time(self, time=None): """ Sets the end time of the vote. :param time: time in unix time :return: """ with session_manager() as session: self.end_time = time session.execute( update(Votes).filter_by(vote_id=self.id).values(end_time=time)) session.commit()
def get_rfr_message_emoji_roles(self, emoji_role_id: int): """ Returns all the emoji-role combinations on an rfr message :param emoji_role_id: emoji-role combo identifier :return: List of rows in the database if found, otherwise None """ with session_manager() as session: rows = session.execute(select(RFRMessageEmojiRoles).filter_by(emoji_role_id=emoji_role_id)).scalars().all() return [(row.emoji_role_id, row.emoji_raw, row.role_id) for row in rows]
def get_ignore_list_users(self, guild_id): """ Get lists of ignored users :param guild_id: The guild id to get the list from :return: list of ignored users """ with session_manager() as session: rows = session.execute(select(TextFilterIgnoreList.ignore) .filter_by(guild_id=guild_id, ignore_type="user")).all() return [row[0] for row in rows]
async def test_disable_verification(): with session_manager() as session: config = dpytest.get_config() guild = config.guilds[0] role = dpytest.back.make_role("testRole", guild, id_num=555) session.add(Roles(s_id=guild.id, r_id=555, email_suffix="egg.com")) session.commit() await dpytest.message(koalabot.COMMAND_PREFIX + "removeVerification egg.com <@&555>") assert dpytest.verify().message().content("Emails ending with egg.com no longer give <@&555>") entry = session.execute(select(Roles).filter_by(s_id=guild.id, r_id=role.id)).all() assert not entry
def new_mod_channel(self, guild_id, channel_id): """ Adds new filtered word for a guild :param guild_id: Guild ID to retrieve filtered words from :param channel_id: The new channel for moderation :return: """ with session_manager() as session: session.add(TextFilterModeration(channel_id=channel_id, guild_id=guild_id)) session.commit()
def get_guild_rfr_messages(self, guild_id: int): """ Gets all rfr messages in a given guild, from the guild ID :param guild_id: ID of the guild :return: List of rfr messages in the guild. """ with session_manager() as session: messages = session.execute(select(GuildRFRMessages) .filter_by(guild_id=guild_id)).scalars().all() return [message.old_format() for message in messages]
def get_mod_channel(self, guild_id): """ Gets specific mod channels given a guild id :param guild_id: Guild ID to retrieve mod channel from :return: list of mod channels """ with session_manager() as session: rows = session.execute(select(TextFilterModeration.channel_id) .filter_by(guild_id=guild_id)).all() return rows
def test_votemanager_load_from_db(): with session_manager() as session: populate_vote_tables(session) vote_manager.load_from_db() assert vote_manager.vote_lookup[(222, "Test Vote 1")] == 111 vote = vote_manager.sent_votes[111] assert vote.target_roles == [999] assert vote.options[1].id == 888 assert vote.options[1].head == "vote1opt" assert vote.options[1].body == "vote1body" assert vote.sent_to[777] == 666
async def test_add_mod_channel(tf_cog): with session_manager() as session: channel = dpytest.backend.make_text_channel( name="TestChannel", guild=dpytest.get_config().guilds[0]) dpytest.get_config().channels.append(channel) await dpytest.message(koalabot.COMMAND_PREFIX + "setupModChannel " + str(channel.id)) assert_embed = create_new_mod_channel_embed(channel) assert dpytest.verify().message().embed(embed=assert_embed) cleanup(dpytest.get_config().guilds[0].id, tf_cog, session)
def test_add_team_to_ta(twitch_alert_db_manager_tables): twitch_alert_db_manager_tables.add_team_to_ta(channel_id=566, twitch_team="faze", custom_message=None, guild_id=568) sql_select_team = select(TeamInTwitchAlert.custom_message)\ .where(and_(TeamInTwitchAlert.channel_id == 566, TeamInTwitchAlert.twitch_team_name == 'faze')) with session_manager() as session: result: TeamInTwitchAlert = session.execute(sql_select_team).fetchone() assert result.custom_message is None
def test_add_user_to_ta_custom_message(twitch_alert_db_manager_tables): twitch_alert_db_manager_tables.new_ta(1234, 1234567892, None) twitch_alert_db_manager_tables.add_user_to_ta( 1234567892, "monstercat", "FiddleSticks {user} is live!", 1234) sql_find_twitch_alert = select(UserInTwitchAlert.twitch_username, UserInTwitchAlert.custom_message)\ .where(and_(UserInTwitchAlert.channel_id == 1234567892, UserInTwitchAlert.twitch_username == 'monstercat')) with session_manager() as session: result: TwitchAlerts = session.execute( sql_find_twitch_alert).fetchone() assert result.twitch_username == 'monstercat' assert result.custom_message == "FiddleSticks {user} is live!"
async def assign_roles_on_startup(self): with session_manager() as session: results = session.execute( select(Roles.s_id, Roles.r_id, Roles.email_suffix)).all() for g_id, r_id, suffix in results: try: guild = self.bot.get_guild(g_id) role = discord.utils.get(guild.roles, id=r_id) await self.assign_role_to_guild(guild, role, suffix) except AttributeError as e: # bot not in guild logger.error(e)