Ejemplo n.º 1
0
 async def member_verification(self, channel, member):
     user_db_lookup = db.query([
         "SELECT osu_id, osu_username FROM users WHERE user_id = ?",
         [str(member.id)]
     ])
     if user_db_lookup:
         ranked_amount = await self.count_ranked_beatmapsets(
             await osu.get_beatmapsets(u=str(user_db_lookup[0][0])))
         role = await self.get_role_based_on_reputation(
             member.guild, ranked_amount)
         await member.add_roles(role)
         osu_profile = await self.get_osu_profile(user_db_lookup[0][0])
         if osu_profile:
             name = osu_profile.name
             embed = await osuembed.user(osu_profile)
         else:
             name = user_db_lookup[0][1]
             embed = None
         await member.edit(nick=name)
         await channel.send(
             f"Welcome aboard {member.mention}! Since we know who you are, "
             "I have automatically gave you appropriate roles. Enjoy your stay!",
             embed=embed)
     else:
         osu_profile = await self.get_osu_profile(member.name)
         if osu_profile:
             await channel.send(
                 content=
                 f"Welcome {member.mention}! We have a verification system in this server "
                 "so we can give you appropriate roles and keep raids/spam out. \n"
                 "Is this your osu! profile? "
                 "If yes, type `yes`, if not, post a link to your profile.",
                 embed=await osuembed.user(osu_profile))
         else:
             await channel.send(
                 f"Welcome {member.mention}! We have a verification system in this server "
                 "so we can give you appropriate roles and keep raids/spam out. \n"
                 "Please post a link to your osu! profile and I will verify you instantly."
             )
Ejemplo n.º 2
0
 async def on_guild_channel_delete(self, deleted_channel):
     try:
         db.query([
             "DELETE FROM mapset_channels WHERE channel_id = ?",
             [str(deleted_channel.id)]
         ])
         db.query([
             "DELETE FROM mod_tracking WHERE channel_id = ?",
             [str(deleted_channel.id)]
         ])
         db.query([
             "DELETE FROM mod_posts WHERE channel_id = ?",
             [str(deleted_channel.id)]
         ])
         print(f"channel {deleted_channel.name} is deleted")
     except Exception as e:
         print(e)
Ejemplo n.º 3
0
 async def pick_message(self, message, depended_channel_id):
     all_potential_messages = db.query(["SELECT * FROM mmj_message_logs "
                                        "WHERE channel_id = ? AND bot = ? AND deleted = ?", 
                                        [str(depended_channel_id), "0", "0"]])
     if all_potential_messages:
         counter = 0
         while True:
             if counter > 50:
                 print("I looked over 50 random messages to send but nothing passed the check.")
                 return False
             counter += 1
             message_from_db = random.choice(all_potential_messages)
             if await self.check_privacy(message):
                 self.bot.get_channel(int(depended_channel_id))
                 picked_message = await message.channel.fetch_message(message_from_db[3])
                 content_to_send = picked_message.content
             else:
                 content_to_send = str(message_from_db[6])
             if await self.check_message_contents(content_to_send):
                 return content_to_send
     else:
         print("The query returned nothing")
         return False
Ejemplo n.º 4
0
 async def add(self, ctx, *, user_name: str):
     role_id_list = db.query([
         "SELECT role_id FROM mapset_channels "
         "WHERE user_id = ? AND channel_id = ?",
         [str(ctx.author.id), str(ctx.channel.id)]
     ])
     if role_id_list:
         try:
             member = self.get_member_guaranteed(ctx, user_name)
             if member:
                 role = discord.utils.get(ctx.guild.roles,
                                          id=int(role_id_list[0][0]))
                 await member.add_roles(role, reason="added to mapset")
                 await ctx.send(f"added {member.mention} in this channel")
             else:
                 await ctx.send(
                     "No member found with what you specified. "
                     "If you are specifying a name, names are case sensitive."
                 )
         except Exception as e:
             await ctx.send(e)
     else:
         await ctx.send("not your mapset channel")
Ejemplo n.º 5
0
    async def untrack(self, ctx):
        mapset_owner_check = db.query([
            "SELECT * FROM mapset_channels "
            "WHERE user_id = ? AND channel_id = ?",
            [str(ctx.author.id), str(ctx.channel.id)]
        ])
        if not (mapset_owner_check or await permissions.is_admin(ctx)):
            return None

        db.query([
            "DELETE FROM mod_tracking WHERE channel_id = ?",
            [str(ctx.channel.id)]
        ])
        db.query([
            "DELETE FROM mod_posts WHERE channel_id = ?",
            [str(ctx.channel.id)]
        ])
        db.query([
            "DELETE FROM mapset_events WHERE channel_id = ?",
            [str(ctx.channel.id)]
        ])
        await ctx.send("Untracked everything in this channel")
Ejemplo n.º 6
0
    async def nuke(self, ctx):
        role_id = db.query([
            "SELECT role_id FROM mapset_channels "
            "WHERE channel_id = ?", [str(ctx.channel.id)]
        ])
        if role_id:
            try:
                await ctx.send(
                    "nuking channel and role in 2 seconds! untracking also")
                await asyncio.sleep(2)
                role = discord.utils.get(ctx.guild.roles,
                                         id=int(role_id[0][0]))

                db.query([
                    "DELETE FROM mod_tracking "
                    "WHERE channel_id = ?", [str(ctx.channel.id)]
                ])
                db.query([
                    "DELETE FROM mod_posts "
                    "WHERE channel_id = ?", [str(ctx.channel.id)]
                ])
                await ctx.send("untracked")
                await asyncio.sleep(2)

                db.query([
                    "DELETE FROM mapset_channels "
                    "WHERE channel_id = ?", [str(ctx.channel.id)]
                ])
                await role.delete(reason="manually nuked the role due to abuse"
                                  )
                await ctx.channel.delete(
                    reason="manually nuked the channel due to abuse")
            except Exception as e:
                await ctx.send(e)
        else:
            await ctx.send("this is not a mapset channel")
Ejemplo n.º 7
0
def create_tables():
    if not os.path.exists(database_file):
        db.query(
            "CREATE TABLE users "
            "(user_id, osu_id, osu_username, osu_join_date, pp, country, ranked_maps_amount, no_sync)"
        )
        db.query(
            "CREATE TABLE user_event_history (osu_id, event_id, channel_id, timestamp)"
        )
        db.query("CREATE TABLE config (setting, parent, value, flag)")

        db.query("CREATE TABLE channels (setting, guild_id, channel_id)")
        db.query("CREATE TABLE categories (setting, guild_id, category_id)")
        db.query("CREATE TABLE roles (setting, guild_id, role_id)")

        db.query("CREATE TABLE admins (user_id, permissions)")
        db.query("CREATE TABLE mod_posts (post_id, mapset_id, channel_id)")
        db.query(
            "CREATE TABLE mapset_events (event_id, mapset_id, channel_id)")
        db.query("CREATE TABLE mod_tracking (mapset_id, channel_id, mode)")
        db.query(
            "CREATE TABLE mod_tracking_pauselist (mapset_id, channel_id, mode)"
        )
        db.query(
            "CREATE TABLE mapset_notification_status (mapset_id, map_id, channel_id, status)"
        )
        db.query("CREATE TABLE map_owners (map_id, user_id)")
        db.query("CREATE TABLE notices (timestamp, notice)")
        db.query("CREATE TABLE restricted_users (guild_id, osu_id)")
        db.query("CREATE TABLE queues (channel_id, user_id, guild_id)")
        db.query(
            "CREATE TABLE mapset_channels (channel_id, role_id, user_id, mapset_id, guild_id)"
        )
        db.query("CREATE TABLE name_backups (id, name)")
        db.query("CREATE TABLE member_goodbye_messages (message)")
        db.query([
            "INSERT INTO member_goodbye_messages VALUES (?)",
            ["%s is going for loved"]
        ])
        db.query([
            "INSERT INTO member_goodbye_messages VALUES (?)",
            ["%s was told to remap one too many times"]
        ])
Ejemplo n.º 8
0
    async def mapset_id_verification(self, message, mapset_id):
        channel = message.channel
        member = message.author
        try:
            mapset = await osu.get_beatmapset(s=mapset_id)
        except:
            await channel.send(
                "i am having connection issues to osu servers, verifying you. "
                "<@155976140073205761> should look into this")
            return None

        if not mapset:
            await channel.send(
                "verification failure, I can\'t find any map with that link")
            return None

        try:
            is_not_restricted = await osu.get_user(u=mapset.creator_id)
            if is_not_restricted:
                await channel.send(
                    "verification failure, "
                    "verification through mapset is reserved for restricted users only"
                )
                return None
        except:
            pass

        ranked_amount = await self.count_ranked_beatmapsets(
            await osu.get_beatmapsets(u=str(mapset.creator_id)))
        role = await self.get_role_based_on_reputation(member.guild,
                                                       ranked_amount)

        check_if_new_discord_account = db.query([
            "SELECT user_id FROM users "
            "WHERE osu_id = ?", [str(mapset.creator_id)]
        ])
        if check_if_new_discord_account:
            if str(check_if_new_discord_account[0][0]) != str(member.id):
                old_user_id = check_if_new_discord_account[0][0]
                await channel.send(
                    f"this osu account is already linked to <@{old_user_id}> in my database. "
                    "if there's a problem, for example, you got a new discord account, ping kyuunex."
                )
                return None

        already_linked_to = db.query(
            ["SELECT osu_id FROM users WHERE user_id = ?", [str(member.id)]])
        if already_linked_to:
            if str(mapset.creator_id) != already_linked_to[0][0]:
                await channel.send(
                    f"{member.mention} it seems like your discord account is already in my database "
                    f"and is linked to <https://osu.ppy.sh/users/{already_linked_to[0][0]}>"
                )
                return None
            else:
                try:
                    await member.add_roles(role)
                    await member.edit(nick=mapset.creator)
                except:
                    pass
                await channel.send(
                    content=
                    f"{member.mention} i already know lol. here, have some roles"
                )
                return None

        try:
            await member.add_roles(role)
            await member.edit(nick=mapset.creator)
        except:
            pass
        embed = await osuembed.beatmapset(mapset)
        db.query(["DELETE FROM users WHERE user_id = ?", [str(member.id)]])
        db.query([
            "INSERT INTO users VALUES (?,?,?,?,?,?,?,?)",
            [
                str(member.id),
                str(mapset.creator_id),
                str(mapset.creator), "", "", "",
                str(ranked_amount), "0"
            ]
        ])
        await channel.send(
            content=f"`Verified through mapset: {member.name}` \n"
            f"You should also read the rules if you haven't already.",
            embed=embed)
Ejemplo n.º 9
0
 async def claim_diff(self, ctx, *, map_id):
     db.query([
         "INSERT INTO map_owners VALUES (?, ?)",
         [str(map_id), str(ctx.author.id)]
     ])
Ejemplo n.º 10
0
 def __init__(self, bot):
     self.bot = bot
     self.voice_logging_channels = db.query(
         "SELECT guild_id, channel_id FROM voice_logging_channels")
Ejemplo n.º 11
0
 async def sql(self, ctx, *, query):
     if len(query) > 0:
         response = db.query(query)
         await ctx.send(response)
Ejemplo n.º 12
0
    async def member_name_syncing_loop(self):
        print("Member Name Syncing Loop launched!")
        await self.bot.wait_until_ready()
        while not self.bot.is_closed():
            await asyncio.sleep(10)
            print(
                time.strftime("%X %x %Z") +
                " | member_name_syncing_loop start")
            user_list = db.query("SELECT * FROM users")
            restricted_user_list = db.query(
                "SELECT guild_id, osu_id FROM restricted_users")
            for mapping_feed_channel_id in self.member_mapping_feed_list:

                feed_channel = self.bot.get_channel(
                    int(mapping_feed_channel_id[1]))
                guild = self.bot.get_guild(int(mapping_feed_channel_id[0]))

                guild_notices_channel = db.query([
                    "SELECT channel_id FROM channels "
                    "WHERE setting = ? AND guild_id = ?",
                    ["notices", str(guild.id)]
                ])

                notices_channel = self.bot.get_channel(
                    int(guild_notices_channel[0][0]))

                for member in guild.members:
                    if member.bot:
                        continue
                    for db_user in user_list:
                        if str(member.id) == str(db_user[0]):
                            try:
                                osu_profile = await osu.get_user(
                                    u=db_user[1], event_days="1")
                            except Exception as e:
                                print(e)
                                await asyncio.sleep(120)
                                break
                            if osu_profile:
                                await self.sync_nickname(
                                    notices_channel, db_user, member,
                                    osu_profile)
                                await self.check_events(
                                    feed_channel, osu_profile)
                                if (str(guild.id), str(
                                        db_user[1])) in restricted_user_list:
                                    await notices_channel.send(
                                        f"{member.mention} | `{db_user[2]}` | `{db_user[1]}` | "
                                        f"<https://osu.ppy.sh/users/{db_user[1]}> | unrestricted lol"
                                    )
                                    db.query([
                                        "DELETE FROM restricted_users "
                                        "WHERE guild_id = ? AND osu_id = ?",
                                        [str(guild.id),
                                         str(db_user[1])]
                                    ])
                            else:
                                # at this point we are sure that the user is restricted.
                                if not (str(guild.id), str(
                                        db_user[1])) in restricted_user_list:
                                    await notices_channel.send(
                                        f"{member.mention} | `{db_user[2]}` | `{db_user[1]}` | "
                                        f"<https://osu.ppy.sh/users/{db_user[1]}> | restricted"
                                    )
                                    db.query([
                                        "INSERT INTO restricted_users VALUES (?,?)",
                                        [str(guild.id),
                                         str(db_user[1])]
                                    ])
                            await asyncio.sleep(1)
            print(
                time.strftime("%X %x %Z") +
                " | member_name_syncing_loop finished")
            await asyncio.sleep(7200)
Ejemplo n.º 13
0
 def __init__(self, bot):
     self.bot = bot
     self.regular_roles = db.query(
         "SELECT guild_id, role_id, threshold FROM regular_roles")
Ejemplo n.º 14
0
def create_tables():
    if not os.path.exists(database_file):
        db.query("CREATE TABLE config (setting, parent, value, flag)")
        db.query("CREATE TABLE admins (user_id, permissions)")
        db.query(
            "CREATE TABLE bridged_extensions (channel_id, extension_name)")

        db.query("CREATE TABLE pinning_history (message_id)")
        db.query("CREATE TABLE pinning_channel_blacklist (channel_id)")
        db.query(
            "CREATE TABLE pinning_channels (guild_id, channel_id, threshold)")

        db.query("CREATE TABLE aimod_blacklist (word)")

        db.query("CREATE TABLE waifu_claims (owner_id, waifu_id)")

        db.query(
            "CREATE TABLE welcome_messages (guild_id, channel_id, message)")
        db.query(
            "CREATE TABLE goodbye_messages (guild_id, channel_id, message)")

        db.query("CREATE TABLE voice_logging_channels (guild_id, channel_id)")
        db.query("CREATE TABLE wasteland_channels (guild_id, channel_id)")
        db.query(
            "CREATE TABLE wasteland_ignore_channels (guild_id, channel_id)")
        db.query("CREATE TABLE regular_roles (guild_id, role_id, threshold)")
        db.query(
            "CREATE TABLE regular_roles_user_blacklist (guild_id, user_id)")
        db.query("CREATE TABLE voice_roles (guild_id, channel_id, role_id)")
        db.query("CREATE TABLE assignable_roles (guild_id, role_id)")
        db.query(
            "CREATE TABLE assignable_roles_user_blacklist (user_id, role_id)")
        db.query("CREATE TABLE cr_pair (command_id, response_id)")

        db.query(
            "CREATE TABLE mmj_message_logs "
            "(guild_id, channel_id, user_id, message_id, username, bot, contents, timestamp, deleted)"
        )
        db.query(
            "CREATE TABLE mmj_channel_bridges (channel_id, depended_channel_id)"
        )
        db.query("CREATE TABLE mmj_stats_channel_blacklist (channel_id)")

        db.query("CREATE TABLE mmj_private_channels (channel_id)")
        db.query("CREATE TABLE mmj_private_categories (category_id)")
        db.query("CREATE TABLE mmj_private_guilds (guild_id)")

        db.query("CREATE TABLE mmj_word_blacklist (word)")
        db.query(
            "CREATE TABLE mmj_responses (trigger, response, type, one_in)")
        db.query(["INSERT INTO mmj_word_blacklist VALUES (?)", ["@"]])
        db.query(
            ["INSERT INTO mmj_word_blacklist VALUES (?)", ["discord.gg/"]])
        db.query(["INSERT INTO mmj_word_blacklist VALUES (?)", ["https://"]])
        db.query(["INSERT INTO mmj_word_blacklist VALUES (?)", ["http://"]])
        db.query(["INSERT INTO mmj_word_blacklist VALUES (?)", ["momiji"]])
        db.query(["INSERT INTO mmj_word_blacklist VALUES (?)", [":gw"]])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["^", "I agree!", "startswith", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["gtg", "nooooo don\'t leaveeeee!", "is", "4"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["kakushi", "kotoga", "is", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["kasanari", "AAAAAAAAAAAAUUUUUUUUUUUUUUUUU", "is", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["giri giri", "EYEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", "is", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["awoo", "awoooooooooooooooooooooooooo", "startswith", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["cya", "nooooo don\'t leaveeeee!", "is", "4"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["bad bot", ";w;", "is", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["stupid bot", ";w;", "is", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["good bot", "^w^", "is", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["sentient", "yes ^w^", "in", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["it is self aware", "yes", "is", "1"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["...", "", "startswith", "10"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["omg", "", "startswith", "10"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["wut", "", "startswith", "10"]
        ])
        db.query([
            "INSERT INTO mmj_responses VALUES (?, ?, ?, ?)",
            ["wat", "", "startswith", "10"]
        ])
Ejemplo n.º 15
0
    "cogs.MomijiSpeak",
    "cogs.Music",
    "cogs.Pinning",
    "cogs.RegularRole",
    "cogs.SelfAssignableRoles",
    "cogs.StatsBuilder",
    "cogs.Utilities",
    "cogs.VoiceLogging",
    "cogs.VoiceRoles",
    "cogs.Waifu",
    "cogs.Welcome",
    "cogs.Wasteland",
    "cogs.WastelandConfiguration",
]

bridged_extensions = db.query("SELECT extension_name FROM bridged_extensions")


class Momiji(commands.Bot):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.background_tasks = []
        self.app_version = (open(".version", "r+").read()).rstrip()
        self.description = f"Momiji {self.app_version}"

        for extension in initial_extensions:
            try:
                self.load_extension(extension)
            except Exception as e:
                print(e)
        for bridged_extension in bridged_extensions:
Ejemplo n.º 16
0
 async def sayonara(self, ctx):
     await ctx.send("sayonara...")
     await ctx.guild.leave()
     db.query([
         "DELETE FROM pinning_channels WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM welcome_messages WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM goodbye_messages WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM voice_logging_channels WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM wasteland_channels WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM wasteland_ignore_channels WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM regular_roles WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM voice_roles WHERE guild_id = ?", [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM assignable_roles WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     db.query([
         "DELETE FROM mmj_message_logs WHERE guild_id = ?",
         [str(ctx.guild.id)]
     ])
     print(f"i forgot about {ctx.guild.name}")
Ejemplo n.º 17
0
    async def user_stats(self, ctx, *args):
        if not await cooldown.check(str(ctx.author.id), "last_stat_time", 40):
            if not await permissions.is_admin(ctx):
                await ctx.send("slow down bruh")
                return None

        async with ctx.channel.typing():
            if "month" in args:
                after = int(time.time()) - 2592000
            elif "week" in args:
                after = int(time.time()) - 604800
            elif "day" in args:
                after = int(time.time()) - 86400
            else:
                after = 0

            scope_key = "guild_id"
            scope_value = str(ctx.guild.id)
            for arg in args:
                if "channel" in arg:
                    scope_key = "channel_id"
                    scope_value = str(ctx.channel.id)
                    if ":" in arg:
                        sub_args = arg.split(":")
                        scope_value = str(sub_args[1])

            query = ["SELECT user_id FROM mmj_message_logs "
                     f"WHERE {scope_key} = ? AND bot = ? AND timestamp > ?",
                     [str(scope_value), str("0"), str(after)]]

            if "all_channels" not in args:
                no_xp_channel_list = db.query("SELECT * FROM mmj_stats_channel_blacklist")
                if no_xp_channel_list:
                    for one_no_xp_channel in no_xp_channel_list:
                        query[0] += f" AND channel_id != '{one_no_xp_channel[0]}'"

            messages = db.query(query)

            stats = await self.list_sorter(messages)
            total_amount = len(messages)

            rank = 0
            contents = ""

            for member_id in stats:
                user_info = db.query(["SELECT username FROM mmj_message_logs WHERE user_id = ?",
                                      [str(member_id[0][0])]])
                member = ctx.guild.get_member(int(member_id[0][0]))
                if not member:
                    member_name = user_info[0][0]
                else:
                    member_name = member.name

                if not str(member_id[0][0]) == "456226577798135808":

                    rank += 1
                    contents += f"**[{rank}]**"
                    contents += " : "

                    contents += f"`{member_name}`"
                    contents += " : "

                    if member:
                        if member.nick:
                            if member.nick != member_name:
                                contents += f"`{member.nick}`"
                                contents += " : "

                    contents += f"{member_id[1]} msgs"
                    contents += "\n"
                    if rank == 40:
                        break

            embed = discord.Embed(description=contents, color=0xffffff)
            embed.set_author(name="User stats")
            embed.set_footer(text=f"Total amount of messages sent: {total_amount}")
        await ctx.send(embed=embed)
Ejemplo n.º 18
0
 def __init__(self, bot):
     self.bot = bot
     self.art_dir = "data/art/"
     self.google_api_key = db.query(["SELECT value FROM config WHERE setting = ?", ["google_api_key"]])
     self.google_search_engine_id = db.query(["SELECT value FROM config WHERE setting = ?",
                                              ["google_search_engine_id"]])
Ejemplo n.º 19
0
 async def make_admin(self, ctx, user_id: str, perms=str("0")):
     db.query(
         ["INSERT INTO admins VALUES (?, ?)", [str(user_id),
                                               str(perms)]])
     await ctx.send(":ok_hand:")
Ejemplo n.º 20
0
 def __init__(self, bot):
     self.bot = bot
     self.veto_channel_list = db.query(
         ["SELECT channel_id FROM channels WHERE setting = ?", ["veto"]])
     self.bot.background_tasks.append(
         self.bot.loop.create_task(self.mod_checker_background_loop()))
Ejemplo n.º 21
0
 def __init__(self, bot):
     self.bot = bot
     self.db_dump_channel_list = db.query([
         "SELECT value FROM config WHERE setting = ?", ["db_dump_channel"]
     ])
Ejemplo n.º 22
0
    async def track(self, ctx, tracking_mode="timeline"):
        mapset_owner_check = db.query([
            "SELECT * FROM mapset_channels "
            "WHERE user_id = ? AND channel_id = ?",
            [str(ctx.author.id), str(ctx.channel.id)]
        ])
        if not (mapset_owner_check or await permissions.is_admin(ctx)):
            return None

        if tracking_mode.isdigit():
            await ctx.send("you are using the command incorrectly")
            return None
        else:
            if tracking_mode == "timeline":
                tracking_mode = "timeline"
            elif tracking_mode == "notification":
                tracking_mode = "notification"
            else:
                await ctx.send("you are using the command incorrectly")
                return None

        if db.query([
                "SELECT mapset_id FROM mod_tracking WHERE channel_id = ?",
            [str(ctx.channel.id)]
        ]):
            db.query([
                "DELETE FROM mod_tracking WHERE channel_id = ?",
                [str(ctx.channel.id)]
            ])
            db.query([
                "DELETE FROM mod_posts WHERE channel_id = ?",
                [str(ctx.channel.id)]
            ])
            db.query([
                "DELETE FROM mapset_events WHERE channel_id = ?",
                [str(ctx.channel.id)]
            ])
            await ctx.send(
                "Deleted all previously existing tracking records in this channel"
            )
            await asyncio.sleep(1)

        mapset_id = db.query([
            "SELECT mapset_id FROM mapset_channels "
            "WHERE channel_id = ?", [str(ctx.channel.id)]
        ])
        if not mapset_id:
            await ctx.send(
                "Set a mapset id for this channel first, using the `'set_id (mapset_id)` command."
            )
            return None
        if str(mapset_id[0][0]) == "0":
            await ctx.send(
                "Set a mapset id for this channel first, using the `'set_id (mapset_id)` command."
            )
            return None

        discussions = await osuweb.get_beatmapset_discussions(
            str(mapset_id[0][0]))
        if not discussions:
            await ctx.send(
                "I am unable to find a modding v2 page for this mapset")
            return None

        if discussions["beatmapset"]["status"] == "graveyard" or discussions[
                "beatmapset"]["status"] == "ranked":
            await ctx.send("i refuse to track graveyarded and ranked sets")
            return None

        if tracking_mode == "timeline":
            await self.insert_mod_history_in_db(discussions,
                                                str(ctx.channel.id))

        await self.insert_nomination_history_in_db(discussions,
                                                   str(ctx.channel.id))

        db.query([
            "INSERT INTO mod_tracking VALUES (?,?,?)",
            [str(mapset_id[0][0]),
             str(ctx.channel.id), tracking_mode]
        ])
        try:
            beatmap_object = await osu.get_beatmapset(s=str(mapset_id[0][0]))
            embed = await osuembed.beatmapset(beatmap_object)

            await ctx.send("Tracked", embed=embed)
            try:
                await self.unarchive_channel(ctx, "mapset")
            except:
                pass
        except:
            await ctx.send("Connection issues? try again")
Ejemplo n.º 23
0
 def __init__(self, bot):
     self.bot = bot
     self.wasteland_channels = db.query(
         "SELECT guild_id, channel_id FROM wasteland_channels")
     self.wasteland_ignore_channels = db.query(
         "SELECT channel_id FROM wasteland_ignore_channels")
Ejemplo n.º 24
0
    async def mod_checker_background_loop(self):
        print("Mod checking Background Loop launched!")
        await self.bot.wait_until_ready()
        while not self.bot.is_closed():
            for track_entry in db.query("SELECT * FROM mod_tracking"):
                print(time.strftime("%X %x %Z") + " | " + track_entry[0])
                channel = self.bot.get_channel(int(track_entry[1]))

                if not channel:
                    print(
                        f"channel {track_entry[1]} is deleted for mapset {track_entry[0]}"
                    )
                    db.query([
                        "DELETE FROM mod_tracking WHERE channel_id = ?",
                        [str(track_entry[1])]
                    ])
                    db.query([
                        "DELETE FROM mod_posts WHERE channel_id = ?",
                        [str(track_entry[1])]
                    ])
                    db.query([
                        "DELETE FROM mapset_channels  WHERE channel_id = ?",
                        [str(track_entry[1])]
                    ])
                    db.query([
                        "DELETE FROM mapset_events  WHERE channel_id = ?",
                        [str(track_entry[1])]
                    ])
                    continue

                mapset_id = str(track_entry[0])
                tracking_mode = str(track_entry[2])

                if not db.query([
                        "SELECT * FROM mod_tracking "
                        "WHERE mapset_id = ? AND channel_id = ? AND mode = ?",
                    [str(mapset_id),
                     str(channel.id),
                     str(tracking_mode)]
                ]):
                    continue

                try:
                    discussions = await osuweb.get_beatmapset_discussions(
                        mapset_id)
                    if not discussions:
                        continue
                except Exception as e:
                    print(e)
                    await asyncio.sleep(300)
                    continue

                if not await self.check_status(channel, mapset_id,
                                               discussions):
                    continue

                if tracking_mode == "veto" or tracking_mode == "timeline":
                    await self.timeline_mode_tracking(discussions, channel,
                                                      mapset_id, tracking_mode)
                elif tracking_mode == "notification":
                    await self.notification_mode_tracking(
                        discussions, channel, mapset_id)

                await self.check_nomination_status(discussions, channel,
                                                   mapset_id, tracking_mode)
                await asyncio.sleep(120)
            await asyncio.sleep(1800)
Ejemplo n.º 25
0
 async def list_mapset_channels(self, ctx):
     for channel in db.query("SELECT * FROM mapset_channels"):
         await ctx.send(
             "channel_id <#%s> | role_id %s | user_id <@%s> | mapset_id %s | guild_id %s "
             % channel)
Ejemplo n.º 26
0
 async def get_role_from_db(self, setting, guild):
     role_id = db.query([
         "SELECT role_id FROM roles WHERE setting = ? AND guild_id = ?",
         [setting, str(guild.id)]
     ])
     return discord.utils.get(guild.roles, id=int(role_id[0][0]))
Ejemplo n.º 27
0
    async def make_mapset_channel(self,
                                  ctx,
                                  mapset_id="0",
                                  *,
                                  mapset_title=None):
        guild_mapset_category_id = db.query([
            "SELECT category_id FROM categories "
            "WHERE setting = ? AND guild_id = ?",
            ["mapset", str(ctx.guild.id)]
        ])

        if not mapset_id.isdigit():
            await ctx.send("first argument must be a number")
            return

        if not guild_mapset_category_id:
            await ctx.send("Not enabled in this server yet.")
            return

        await ctx.send("sure, gimme a moment")

        if mapset_id == "0":
            mapset = None
        else:
            try:
                mapset = await osu.get_beatmapset(s=mapset_id)
                if not mapset:
                    await ctx.send(
                        "you specified incorrect mapset id. "
                        "you can correct this with `'set_id` command in the mapset channel"
                    )
            except Exception as e:
                mapset = None
                print(e)
                await ctx.send(
                    "looks like there are connection issues to osu servers, "
                    "so i'll put in a blank value for the mapset_id "
                    "and later you can update it with `'set_id` command")

        if mapset:
            mapset_id = str(mapset.id)
            channel_topic = str(mapset.url)
        else:
            mapset_id = "0"
            channel_topic = ""

        if mapset_title:
            discord_friendly_channel_name = mapset_title.replace(" ",
                                                                 "_").lower()
            role_name = mapset_title
        elif mapset:
            discord_friendly_channel_name = mapset.title.replace(" ",
                                                                 "_").lower()
            role_name = mapset.title
        else:
            await ctx.send(
                "i was unable to create a mapset channel for you because "
                "you neither specified a valid mapset_id of your mapset (or there are connection issues) "
                "nor a mapset name. "
                "i need at least one to make a mapset channel.")
            return

        guild = ctx.guild
        role_color = discord.Colour(random.randint(1, 16777215))
        mapset_role = await guild.create_role(name=role_name,
                                              colour=role_color,
                                              mentionable=True)
        category = self.bot.get_channel(int(guild_mapset_category_id[0][0]))
        channel_overwrites = {
            guild.default_role:
            discord.PermissionOverwrite(read_messages=False),
            ctx.author: self.mapset_owner_default_permissions,
            mapset_role: discord.PermissionOverwrite(read_messages=True),
            guild.me: self.mapset_bot_default_permissions
        }
        channel = await guild.create_text_channel(
            discord_friendly_channel_name,
            overwrites=channel_overwrites,
            category=category,
            topic=channel_topic)
        await ctx.author.add_roles(mapset_role)
        await channel.send(
            content=f"{ctx.author.mention} done! Please keep in mind that "
            f"I don't automatically start tracking. "
            "You can use the `'track` command bellow to start tracking.",
            embed=await self.docs.mapset_channel_management())
        db.query([
            "INSERT INTO mapset_channels "
            "VALUES (?, ?, ?, ?, ?)",
            [
                str(channel.id),
                str(mapset_role.id),
                str(ctx.author.id),
                str(mapset_id),
                str(ctx.guild.id)
            ]
        ])
        await ctx.send("ok, i'm done!")
Ejemplo n.º 28
0
 def __init__(self, bot):
     self.bot = bot
     self.pinning_channels = db.query(
         "SELECT guild_id, channel_id, threshold FROM pinning_channels")
     self.pinning_channel_blacklist = db.query(
         "SELECT channel_id FROM pinning_channel_blacklist")
Ejemplo n.º 29
0
 async def check_status(self, channel, mapset_id, discussions):
     status = discussions["beatmapset"]["status"]
     if (status == "wip") or (status == "qualified") or (status
                                                         == "pending"):
         return True
     elif status == "graveyard":
         db.query([
             "DELETE FROM mod_tracking WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         db.query([
             "DELETE FROM mod_posts WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         db.query([
             "DELETE FROM mapset_events WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         await channel.send(
             content="This mapset is graveyarded, so I am untracking it. "
             "I don't wanna track dead sets. "
             "You can track again after it's ungraveyarded "
             f"https://osu.ppy.sh/beatmapsets/{mapset_id}")
         return None
     elif status == "deleted":
         db.query([
             "DELETE FROM mod_tracking WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         db.query([
             "DELETE FROM mod_posts WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         db.query([
             "DELETE FROM mapset_events WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         await channel.send(
             content="This mapset is deleted, so I am untracking it. "
             "why tho????????????? channel archived and will be nuked in a week "
             "along with it's role. "
             f"https://osu.ppy.sh/beatmapsets/{mapset_id}")
         guild_archive_category_id = db.query([
             "SELECT category_id FROM categories "
             "WHERE setting = ? AND guild_id = ?",
             ["mapset_archive", str(channel.guild.id)]
         ])
         if guild_archive_category_id:
             archive_category = self.bot.get_channel(
                 int(guild_archive_category_id[0][0]))
             await channel.edit(reason="mapset deleted!",
                                category=archive_category)
         return None
     elif status == "ranked":
         db.query([
             "DELETE FROM mod_tracking WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         db.query([
             "DELETE FROM mod_posts WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         db.query([
             "DELETE FROM mapset_events WHERE mapset_id = ? AND channel_id = ?",
             [str(mapset_id), str(channel.id)]
         ])
         await channel.send(
             content="This mapset is ranked, so I am untracking it. "
             "There is no point in continuing to do so. "
             "Channel archived! "
             f"https://osu.ppy.sh/beatmapsets/{mapset_id}")
         guild_archive_category_id = db.query([
             "SELECT category_id FROM categories "
             "WHERE setting = ? AND guild_id = ?",
             ["mapset_archive", str(channel.guild.id)]
         ])
         if guild_archive_category_id:
             archive_category = self.bot.get_channel(
                 int(guild_archive_category_id[0][0]))
             await channel.edit(reason="mapset ranked!",
                                category=archive_category)
         return None
     else:
         await channel.send(
             content=
             "<@155976140073205761> something went wrong, please check the console output."
         )
         print(f"{status} / {mapset_id}")
         return None
Ejemplo n.º 30
0
    async def profile_id_verification(self, message, osu_id):
        channel = message.channel
        member = message.author
        try:
            osu_profile = await osu.get_user(u=osu_id)
        except:
            await channel.send(
                "i am having connection issues to osu servers, verifying you. "
                "<@155976140073205761> should look into this")
            return None

        if not osu_profile:
            if osu_id.isdigit():
                await channel.send(
                    "verification failure, "
                    "i can't find any profile from that link or you are restricted. "
                    "if you are restricted, link any of your recently uploaded maps (new site only)"
                )
            else:
                await channel.send(
                    "verification failure, "
                    "either your discord username does not match a username of any osu account "
                    "or you linked an incorrect profile. "
                    "this error also pops up if you are restricted, in that case, "
                    "link any of your recently uploaded maps (new site only)")
            return None

        ranked_amount = await self.count_ranked_beatmapsets(
            await osu.get_beatmapsets(u=str(osu_profile.id)))
        role = await self.get_role_based_on_reputation(member.guild,
                                                       ranked_amount)

        already_linked_to = db.query(
            ["SELECT osu_id FROM users WHERE user_id = ?", [str(member.id)]])
        if already_linked_to:
            if str(osu_profile.id) != already_linked_to[0][0]:
                await channel.send(
                    f"{member.mention} it seems like your discord account is already in my database and "
                    f"is linked to <https://osu.ppy.sh/users/{already_linked_to[0][0]}>"
                )
                return None
            else:
                try:
                    await member.add_roles(role)
                    await member.edit(nick=osu_profile.name)
                except:
                    pass
                await channel.send(
                    content=
                    f"{member.mention} i already know lol. here, have some roles"
                )
                return None

        check_if_new_discord_account = db.query([
            "SELECT user_id FROM users WHERE osu_id = ?",
            [str(osu_profile.id)]
        ])
        if check_if_new_discord_account:
            if str(check_if_new_discord_account[0][0]) != str(member.id):
                old_user_id = check_if_new_discord_account[0][0]
                await channel.send(
                    f"this osu account is already linked to <@{old_user_id}> in my database. "
                    "if there's a problem, for example, you got a new discord account, ping kyuunex."
                )
                return None

        try:
            await member.add_roles(role)
            await member.edit(nick=osu_profile.name)
        except:
            pass
        embed = await osuembed.user(osu_profile)
        db.query(["DELETE FROM users WHERE user_id = ?", [str(member.id)]])
        db.query([
            "INSERT INTO users VALUES (?,?,?,?,?,?,?,?)",
            [
                str(member.id),
                str(osu_profile.id),
                str(osu_profile.name),
                str(osu_profile.join_date),
                str(osu_profile.pp_raw),
                str(osu_profile.country),
                str(ranked_amount), "0"
            ]
        ])
        await channel.send(
            content=f"`Verified: {member.name}` \n"
            f"You should also read the rules if you haven't already.",
            embed=embed)