summaryrefslogtreecommitdiff
path: root/cogs/Synthy.py
blob: 9fbaf38841512c3607133743c477ac95a6b48d9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from discord.ext import commands
import discord
import importlib
import utils
importlib.reload(utils)


class Synthy(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.has_permissions(administrator=True)
    @commands.group(invoke_without_command=True)
    async def synthy(self, ctx):
        """
        Allows you to change the bots nickname for your Discord server
        """
        prefix = await self.bot.get_prefix(ctx.message)

        emb = await utils.embed(ctx, f"Commands for `{prefix[2]}{self.bot.user.name.lower()}`", "")
        emb = await utils.field(emb, f"{prefix[2]}{self.bot.user.name.lower()} nick `[nickname]`",
                                f"Change the nickname for {self.bot.user.name.lower()} on this server.")
        emb = await utils.field(emb, f"{prefix[2]}{self.bot.user.name.lower()} prefix `[prefix]`",
                                f"Change the symbol used for commands from `{prefix[2]}` to another symbol.\n" +
                                "This can be a maximum of 5 characters.")

        await ctx.message.channel.send(embed=emb)

    @commands.has_permissions(administrator=True)
    @synthy.command(aliases=[], application_command_meta=commands.ApplicationCommandMeta(options=[]))
    async def nick(self, ctx, *args):
        try:
            guild = self.bot.get_guild(ctx.message.guild.id)
            member = guild.get_member(self.bot.user.id)
            await member.edit(nick=" ".join(args))
            if ctx.guild.me.permissions_in(ctx.channel).add_reactions:
                await ctx.message.add_reaction("✅")
        except discord.Forbidden as e:
            await ctx.message.channel.send(f"Forbidden: {e}")
        except discord.HTTPException as e:
            await ctx.message.channel.send(f"HTTPException: {e}")
        except Exception as e:
            await ctx.message.channel.send(f"Error: {e}")

    @commands.has_permissions(administrator=True)
    @synthy.command(aliases=[], application_command_meta=commands.ApplicationCommandMeta(options=[]))
    async def activity(self, ctx, *args):
        try:
            await self.bot.change_presence(status=discord.Status.online, activity=discord.Game(name=" ".join(args)))
        except discord.InvalidArgument as e:
            await ctx.message.channel.send(f"InvalidArgument: {e}")
        except Exception as e:
            await ctx.message.channel.send(f"Error: {e}")

    @commands.has_permissions(administrator=True)
    @synthy.command(aliases=[], application_command_meta=commands.ApplicationCommandMeta(options=[]))
    async def prefix(self, ctx, arg):
        await utils.sql('INSERT INTO "database1".synthy.settings (guild_id, bot_name, prefix) VALUES (%s, %s, %s) ON CONFLICT (guild_id, bot_name) DO UPDATE SET prefix = %s;', (ctx.guild.id, self.bot.user.name, arg, arg,))
        emb = await utils.embed(ctx, self.bot.user.name, f"Server prefix set to `{arg}`")
        await ctx.send(embed=emb)
        if ctx.guild.me.permissions_in(ctx.channel).manage_messages:
            await ctx.message.delete()


def setup(bot):
    print("INFO: Loading [Synthy]... ", end="")
    bot.add_cog(Synthy(bot))
    print("Done!")


def teardown(bot):
    print("INFO: Unloading [Synthy]")