1
|
|
|
""" |
2
|
|
|
Cog with general commands available in the Bot. |
3
|
|
|
""" |
4
|
|
|
|
5
|
|
|
import discord |
6
|
|
|
from discord.ext import commands |
7
|
|
|
from discord.utils import get |
8
|
|
|
from discord_slash import cog_ext, SlashContext |
9
|
|
|
from googletrans import Translator |
10
|
|
|
|
11
|
|
|
import cogs.cogbase as cogbase |
12
|
|
|
from cogs.databasecog import DatabaseCog |
13
|
|
|
from modules.utils import get_dominant_color |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class CommandsCog(cogbase.BaseCog): |
17
|
|
|
def __init__(self, base): |
18
|
|
|
super().__init__(base) |
19
|
|
|
|
20
|
|
|
# Get own spotting stats |
21
|
|
|
@cog_ext.cog_slash(name="myStats", guild_ids=cogbase.GUILD_IDS, |
22
|
|
|
description="Get your spotting stats", |
23
|
|
|
default_permission=True) |
24
|
|
|
async def get_stats_own(self, ctx: SlashContext) -> None: |
25
|
|
|
embed = await self.get_stats(ctx.author) |
26
|
|
|
await ctx.send(embed=embed, hidden=True) |
27
|
|
|
|
28
|
|
|
# Get and show own spotting stats |
29
|
|
|
@cog_ext.cog_slash(name="myStatsShow", guild_ids=cogbase.GUILD_IDS, |
30
|
|
|
description="Get your spotting stats and show it to other members", |
31
|
|
|
default_permission=True) |
32
|
|
|
async def show_stats_own(self, ctx: SlashContext) -> None: |
33
|
|
|
embed = await self.get_stats(ctx.author) |
34
|
|
|
await ctx.send(embed=embed) |
35
|
|
|
|
36
|
|
|
# Get member's spotting stats |
37
|
|
|
@cog_ext.cog_slash(name="memberStats", guild_ids=cogbase.GUILD_IDS, |
38
|
|
|
description="Get member's spotting stats", |
39
|
|
|
default_permission=False, |
40
|
|
|
permissions=cogbase.PERMISSION_MODS) |
41
|
|
|
async def get_stats_member(self, ctx: SlashContext, member: discord.Member) -> None: |
42
|
|
|
embed = await self.get_stats(member) |
43
|
|
|
await ctx.send(embed=embed, hidden=True) |
44
|
|
|
|
45
|
|
|
async def get_stats(self, member: discord.Member) -> discord.Embed: |
46
|
|
|
spot_roles = self.bot.config["total_milestones"][0] |
47
|
|
|
guild = self.bot.get_guild(self.bot.guild[0]) |
48
|
|
|
spots_df = await DatabaseCog.db_get_member_stats(member.id) |
49
|
|
|
spots_df["total"] = spots_df["legendary"] * self.legend_multiplier + spots_df["rare"] |
50
|
|
|
|
51
|
|
|
role_next = "" |
52
|
|
|
spots_for_new = "" |
53
|
|
|
roles_list = [key for (key, value) in spot_roles.items() if spots_df.at[0, "total"] < value] |
54
|
|
|
values_list = [value for (key, value) in spot_roles.items() if spots_df.at[0, "total"] < value] |
55
|
|
|
if roles_list: |
56
|
|
|
role_next = get(guild.roles, name=roles_list[0]) |
57
|
|
|
spots_for_new = values_list[0] |
58
|
|
|
|
59
|
|
|
message: str = f"**Legends**: {spots_df.at[0, 'legendary']}\n" \ |
60
|
|
|
f"**Rares**: {spots_df.at[0, 'rare']}\n" \ |
61
|
|
|
f"**Commons**: {spots_df.at[0, 'common']}\n\n" \ |
62
|
|
|
f"**Total points**: {spots_df.at[0, 'total']}\n" \ |
63
|
|
|
f"**Progress**: {spots_df.at[0, 'total']}/{spots_for_new}\n" \ |
64
|
|
|
f"**Next role**: {role_next.name}" |
65
|
|
|
|
66
|
|
|
member_color = get_dominant_color(member.avatar_url) |
67
|
|
|
embed = discord.Embed(title=f"{member} spotting stats", description=message, |
68
|
|
|
color=member_color) |
69
|
|
|
embed.set_thumbnail(url=f'{member.avatar_url}') |
70
|
|
|
return embed |
71
|
|
|
|
72
|
|
|
# Pool |
73
|
|
|
@cog_ext.cog_slash(name="poll", guild_ids=cogbase.GUILD_IDS, |
74
|
|
|
description="Create pool", |
75
|
|
|
default_permission=False, |
76
|
|
|
permissions=cogbase.PERMISSION_MODS) |
77
|
|
|
async def poll(self, ctx: SlashContext, *, title: str, content: str = "") -> None: |
78
|
|
|
author_color = get_dominant_color(ctx.author.avatar_url) |
79
|
|
|
emb = (discord.Embed(title=f"{title}", description=content, color=author_color)) |
80
|
|
|
try: |
81
|
|
|
poll_message = await ctx.send(embed=emb) |
82
|
|
|
await poll_message.add_reaction("\N{THUMBS UP SIGN}") |
83
|
|
|
await poll_message.add_reaction("\N{THUMBS DOWN SIGN}") |
84
|
|
|
except Exception as e: |
85
|
|
|
await ctx.send(f"Oops, I couldn't react to the poll. Check that I have permission to add reactions! " |
86
|
|
|
f"```py\n{e}```", hidden=True) |
87
|
|
|
|
88
|
|
|
# Translate |
89
|
|
|
@cog_ext.cog_slash(name="translate", guild_ids=cogbase.GUILD_IDS, |
90
|
|
|
description="Translate message", |
91
|
|
|
default_permission=False, |
92
|
|
|
permissions=cogbase.PERMISSION_MODS) |
93
|
|
|
async def translate(self, ctx: SlashContext, message: str) -> None: |
94
|
|
|
# Translates the language and converts it to English |
95
|
|
|
translator = Translator() |
96
|
|
|
translated_message = translator.translate(message) |
97
|
|
|
await ctx.send(f"`{message}` -> `{translated_message.text}`", hidden=True) |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
def setup(bot: commands.Bot) -> None: |
101
|
|
|
bot.add_cog(CommandsCog(bot)) |
102
|
|
|
|