Passed
Push — main ( 530a31...c507f0 )
by Bartosz
02:42 queued 01:19
created

ChannelUpCog.rename_nword_channel()   A

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 12
rs 9.85
c 0
b 0
f 0
cc 2
nop 3
1
import discord
2
import cogs.cogbase as cogbase
3
from discord.ext import commands
4
from discord_slash import cog_ext, SlashContext
5
6
7
class ChannelUpCog(cogbase.BaseCog):
8
    def __init__(self, base):
9
        super().__init__(base)
10
11
    # CHANNEL NAMES UPDATES
12
    # Total member channel name
13
    @cog_ext.cog_slash(name="updateTotalMembers", guild_ids=cogbase.GUILD_IDS,
14
                       description="Update total number of members",
15
                       default_permission=False,
16
                       permissions=cogbase.PERMISSION_MODS)
17
    async def update_member_count_command(self, ctx: SlashContext):
18
        await self.bot.update_member_count(ctx)
19
        await ctx.send(f"Total Members count updated", hidden=True)
20
21
    # Commons channel name
22
    @cog_ext.cog_slash(name="updateCommons", guild_ids=cogbase.GUILD_IDS,
23
                       description="Update common channel name",
24
                       default_permission=False,
25
                       permissions=cogbase.PERMISSION_MODS)
26
    async def update_common_ch_name(self, ctx: SlashContext):
27
        with open('./server_files/commons.txt') as f:
28
            try:
29
                commons = f.read().splitlines()
30
            except ValueError:
31
                print(ValueError)
32
33
        await self.update_commons_ch(ctx, commons)
34
35
        commons.append(commons.pop(commons.index(commons[0])))
36
        with open('./server_files/commons.txt', 'w') as f:
37
            for item in commons:
38
                f.write("%s\n" % item)
39
40
    async def update_commons_ch(self, ctx: SlashContext, commons):
41
        new_name = f"common {commons[0]}"
42
        common_ch = self.bot.get_channel(self.bot.ch_common)
43
        await discord.TextChannel.edit(common_ch, name=new_name)
44
        self.create_log_msg(f"Common channel name updated: {commons[0]}")
45
        await common_ch.send(f"Common changed: {commons[0]}")
46
        await ctx.send(f"Common changed: {commons[0]}", hidden=True)
47
48
    # N-Word spotted channel name
49
    # Doesn't work if used too many times in a short period of time
50
    @cog_ext.cog_slash(name="nightmareStatus", guild_ids=cogbase.GUILD_IDS,
51
                       description="Change Nightmare status channel name",
52
                       default_permission=False,
53
                       permissions=cogbase.PERMISSION_ADMINS)
54
    async def rename_nightmare_channel(self, ctx, status: str):
55
        new_status = status
56
        channel = self.bot.get_channel(self.bot.ch_nightmare_killed)
57
        if new_status in channel.name:
58
            await ctx.send(f"{channel.name} has been changed", hidden=True)
59
        else:
60
            await discord.VoiceChannel.edit(channel, name=f"N-Word fixed: {new_status}")
61
            await ctx.send(f"{channel.name} channel name has been changed", hidden=True)
62
63
64
def setup(bot: commands.Bot):
65
    bot.add_cog(ChannelUpCog(bot))
66