1
|
|
|
"""Misc features cog for CCC Bot""" |
2
|
|
|
import random |
3
|
|
|
from datetime import datetime |
4
|
|
|
from discord.ext import commands |
5
|
|
|
from bot import utils |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class MiscCog(commands.Cog, name="Misc"): |
9
|
|
|
"""Misc Cog |
10
|
|
|
|
11
|
|
|
Cog that deal with misc features contains ping, report and uptime. |
12
|
|
|
|
13
|
|
|
**Commands:** |
14
|
|
|
- `ping`: Testing command that will DM the member pong and then delete the ping message. |
15
|
|
|
|
16
|
|
|
- `report`: Report command. When triggered it will ask the member for a reason then ping |
17
|
|
|
all admins with the message. *Might need to be disabled for spam* |
18
|
|
|
|
19
|
|
|
- `uptime`: Lists uptime for bot and when it was started. |
20
|
|
|
|
21
|
|
|
""" |
22
|
|
|
|
23
|
|
|
def __init__(self, bot): |
24
|
|
|
self.bot = bot |
25
|
|
|
|
26
|
|
|
@commands.command(name="ping", help="Testing command that returns pong", hidden=True) |
27
|
|
|
async def ping(self, ctx: commands.Context) -> None: |
28
|
|
|
"""Ping |
29
|
|
|
|
30
|
|
|
Testing command that will message the author pong and delete the author's ping message. |
31
|
|
|
|
32
|
|
|
:param ctx: Command context |
33
|
|
|
:type ctx: discord.ext.commands.Context |
34
|
|
|
:return: None |
35
|
|
|
""" |
36
|
|
|
self.bot.log.debug(f"{ctx.author.name} has sent ping.") |
37
|
|
|
await ctx.message.delete() |
38
|
|
|
embed = await utils.make_embed(ctx, send=False, title="PONG") |
39
|
|
|
url = "https://peterfrezzini.com/content/images/2016/12/pong_logo.jpg" |
40
|
|
|
embed.set_image(url=url) |
41
|
|
|
embed.set_footer(text="Image from https://peterfrezzini.com/pong-game-cover/") |
42
|
|
|
await ctx.author.send(embed=embed) |
43
|
|
|
|
44
|
|
|
@commands.command(name="uptime", help="Gets uptime of bot") |
45
|
|
|
async def uptime(self, ctx: commands.Context) -> None: |
46
|
|
|
""" |
47
|
|
|
Uptime |
48
|
|
|
|
49
|
|
|
Command that shows how long the bot has been online |
50
|
|
|
|
51
|
|
|
:param ctx: Command context |
52
|
|
|
:type ctx: discord.ext.commands.Context |
53
|
|
|
:return: None |
54
|
|
|
""" |
55
|
|
|
uptime = datetime.utcnow() - self.bot.uptime |
56
|
|
|
|
57
|
|
|
uptime = ( |
58
|
|
|
":clock1: Days: {}, Hours: {}, Minutes:{}, Seconds: {}".format( # pylint: disable=C0209 |
59
|
|
|
uptime.days, |
60
|
|
|
uptime.seconds // 3600, # Hours |
61
|
|
|
(uptime.seconds // 60) % 60, # Minutes |
62
|
|
|
uptime.seconds % 60, # Seconds |
63
|
|
|
) |
64
|
|
|
) |
65
|
|
|
|
66
|
|
|
start_time = self.bot.uptime.strftime("%Y-%m-%d %H:%M") |
67
|
|
|
list_string_time = self.bot.list_updated.strftime("%Y-%m-%d %H:%M") |
68
|
|
|
description = ( |
69
|
|
|
f"Bot has been online since {start_time} UTC\n " |
70
|
|
|
f"School list last updated {list_string_time}" |
71
|
|
|
) |
72
|
|
|
|
73
|
|
|
await utils.make_embed( |
74
|
|
|
ctx, title=uptime, description=description, footer=self.bot.__version__ |
75
|
|
|
) |
76
|
|
|
|
77
|
|
|
@commands.command( |
78
|
|
|
name="report", |
79
|
|
|
aliases=["contact-admin"], |
80
|
|
|
help="Reporting feature.\n" |
81
|
|
|
"Use if you are experiencing issues with the bot or in the server.", |
82
|
|
|
) |
83
|
|
|
async def report(self, ctx: commands.Context, *, message: str) -> None: |
84
|
|
|
"""Report |
85
|
|
|
|
86
|
|
|
reporting command. When triggered, member will be prompted for a reason. Message will then |
87
|
|
|
be sent to all bot admins. |
88
|
|
|
|
89
|
|
|
:param ctx: Command context |
90
|
|
|
:type ctx: discord.ext.commands.Context |
91
|
|
|
:param message: Report message sent |
92
|
|
|
:type message: str |
93
|
|
|
:return: None |
94
|
|
|
""" |
95
|
|
|
reports = await utils.fetch("reports", "id") |
96
|
|
|
report_id = random.randint(1, 32767) # nosec |
97
|
|
|
while report_id in reports: |
98
|
|
|
self.bot.log.warning("report_id had to be regenerated") |
99
|
|
|
report_id = random.randint(1, 32767) # nosec |
100
|
|
|
await utils.insert( |
101
|
|
|
"reports", |
102
|
|
|
[ |
103
|
|
|
report_id, |
104
|
|
|
(ctx.author.name + ctx.author.discriminator), |
105
|
|
|
ctx.author.id, |
106
|
|
|
message, |
107
|
|
|
datetime.utcnow(), |
108
|
|
|
], |
109
|
|
|
) |
110
|
|
|
channels = await utils.select("admin_channels", "id", "log", "f") |
111
|
|
|
for channel in channels: |
112
|
|
|
to_send = self.bot.get_channel(channel) |
113
|
|
|
if to_send is None: |
114
|
|
|
self.bot.log.warning(f"No channel found for id channel {channel}") |
115
|
|
|
await utils.make_embed( |
116
|
|
|
ctx, |
117
|
|
|
title="New Report", |
118
|
|
|
description=f"{ctx.author.name} submitted the report:\n> {message}", |
119
|
|
|
) |
120
|
|
|
|
121
|
|
|
response_msg = ( |
122
|
|
|
"The admins have received your report.\nThey will investigation and may reach out" |
123
|
|
|
) |
124
|
|
|
await utils.make_embed(ctx, title="Report Received", description=response_msg) |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
def setup(bot): |
128
|
|
|
"""Needed for extension loading""" |
129
|
|
|
bot.add_cog(MiscCog(bot)) |
130
|
|
|
|