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