def test_update(self): do.add_guild(self.database, "guildname1", 2194828943719823547) do.add_guild(self.database, "deez nuts", 53429781423) do.update_guild_options(self.database, "guildname1", 2194828943719823547, crop_picture=True, safe_picture=True, random_icon_change=True, delete_interval=100) do.update_guild_options(self.database, "deez nuts", 53429781423, safe_picture=True, delete_interval=20) guild_options_1 = do.get_guild_options(self.database, "guildname1", 2194828943719823547) guild_options_2 = do.get_guild_options(self.database, "deez nuts", 53429781423) self.assertEqual(guild_options_1["crop_picture"], True) self.assertEqual(guild_options_1["safe_picture"], True) self.assertEqual(guild_options_1["random_icon_change"], True) self.assertEqual(guild_options_1["delete_interval"], 100) self.assertEqual(guild_options_2["crop_picture"], False) self.assertEqual(guild_options_2["safe_picture"], True) self.assertEqual(guild_options_2["random_icon_change"], False) self.assertEqual(guild_options_2["delete_interval"], 20)
def test_remove(self): do.add_guild(self.database, "guildname1", 2194828943719823547) do.add_guild(self.database, "deez nuts", 53429781423) do.remove_guild(self.database, "guildname1", 2194828943719823547) with self.assertRaises(do.DatabaseException): do.get_guild_options(self.database, "guildname1", 2194828943719823547)
def test_insert_many(self): do.add_guild(self.database, [f"g{i}" for i in range(0, 1000)], [i for i in range(0, 1000)]) cursor = self.database.cursor() cursor.execute("select * from guildoptions;") items = [] for item in cursor.fetchall(): items.append(item) self.assertEqual(len(items), 1000)
def test_insert(self): do.add_guild(self.database, "guildname1", 2194828943719823547) do.add_guild(self.database, "deez nuts", 53429781423) # same name, but different ids do.add_guild(self.database, "funny", 123456789) do.add_guild(self.database, "funny", 987654321)
async def on_guild_join(self, guild: discord.Guild): ''' Add entry to database, if joined to new server ''' if guild in self.bot.guilds: return database_ops.add_guild(self.database, guild.name, guild.id) self.create_guild_folder(guild) self.guild_options[guild] = { "crop_picture": True, "safe_picture": False, "random_icon_change": False, "delete_interval": 0 }
async def on_guild_available(self, guild): print(f"{guild.name} is available") try: guild_options, guild_channels, guild_roles = database_ops.recover_guild( self.database, guild.name, guild.id) self.accepted_roles[guild] = guild_roles self.listen_channels[guild] = guild_channels self.guild_options[guild_roles] = guild_options except DatabaseException as err: if err.reason == "Entry not found": database_ops.add_guild(self.database, guild.name, guild.id) self.guild_options[guild] = { "crop_picture": True, "safe_picture": False, "random_icon_change": False, "delete_interval": 0 }
def test_insert_duplicate(self): do.add_guild(self.database, "gn1", 123456789) with self.assertRaises(do.DatabaseException): do.add_guild(self.database, "gn1", 123456789)
def test_update(self): do.add_guild(self.database, "guildname1", 2194828943719823547) do.update_guild()