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 and contact-admin. |
14
|
|
|
|
15
|
|
|
Commands: |
16
|
|
|
--- |
17
|
|
|
`ping`: Testing command that will DM the user pong and then delete the ping message. |
18
|
|
|
`contact-admin`: 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
|
|
|
|
21
|
|
|
Arguments: |
22
|
|
|
--- |
23
|
|
|
bot {discord.commands.Bot} -- The bot |
24
|
|
|
""" |
25
|
|
|
def __init__(self, bot): |
26
|
|
|
self.bot = bot |
27
|
|
|
self.log = logging.getLogger("bot") |
28
|
|
|
|
29
|
|
|
@commands.command(name="ping", |
30
|
|
|
help="Testing command that returns pong", |
31
|
|
|
hidden=True) |
32
|
|
|
async def ping(self, ctx): |
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/s") |
48
|
|
|
await ctx.author.send(embed=embed) |
49
|
|
|
|
50
|
|
|
@commands.command(name="uptime", |
51
|
|
|
help="Gets uptime of bot") |
52
|
|
|
async def uptime(self, ctx): |
53
|
|
|
"""uptime |
54
|
|
|
--- |
55
|
|
|
|
56
|
|
|
Arguments: |
57
|
|
|
--- |
58
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command. |
59
|
|
|
""" |
60
|
|
|
current_time = datetime.utcnow() |
61
|
|
|
|
62
|
|
|
uptime = current_time - self.bot.uptime |
63
|
|
|
uptime = "Days: {}, Hours: {}, Minutes: {}, Seconds: {}".format(uptime.days, |
64
|
|
|
uptime.seconds // 3600, |
65
|
|
|
uptime.seconds // 60, |
66
|
|
|
uptime.seconds % 60) |
67
|
|
|
start_time = self.bot.uptime.strftime("%Y-%m-%d %H:%M") |
68
|
|
|
description = "Bot has been online since {} UTC".format(start_time) |
69
|
|
|
await utils.make_embed(ctx, title=uptime, |
70
|
|
|
description=description) |
71
|
|
|
|
72
|
|
|
@commands.command(name="report", |
73
|
|
|
aliases=["contact-admin"], |
74
|
|
|
help="Reporting feature.\n" |
75
|
|
|
"Use if you are experaincing issues with the bot or in the server.") |
76
|
|
|
async def contact_admin(self, ctx, *, message: str): |
77
|
|
|
"""Contact-Admin |
78
|
|
|
--- |
79
|
|
|
|
80
|
|
|
A reporting command. When triggered, user will be prompted for a reason. Message will then |
81
|
|
|
be sent to all bot admins. |
82
|
|
|
|
83
|
|
|
Arguments: |
84
|
|
|
--- |
85
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command. |
86
|
|
|
""" |
87
|
|
|
reports = await utils.fetch("reports", "id") |
88
|
|
|
reportID = random.randint(1, 32767) # nosec |
89
|
|
|
while reportID in reports: |
90
|
|
|
self.log.debug("reportID had to be regenerated") |
91
|
|
|
reportID = random.randint(1, 32767) # nosec |
92
|
|
|
await utils.insert("reports", |
93
|
|
|
[reportID, |
94
|
|
|
(ctx.author.name+ctx.author.discriminator), |
95
|
|
|
ctx.author.id, |
96
|
|
|
message, |
97
|
|
|
datetime.utcnow()]) |
98
|
|
|
channels = await utils.select("admin_channels", "id", "log", "f") |
99
|
|
|
for channel in channels: |
100
|
|
|
to_send = self.bot.get_channel(channel) |
101
|
|
|
if to_send is None: |
102
|
|
|
self.log.warning('No channel found for id {}'.format(channel)) |
103
|
|
|
await utils.make_embed(ctx, title="New Report", |
104
|
|
|
description="{} submitted the report:\n> {}" |
105
|
|
|
.format(ctx.author.name, message)) |
106
|
|
|
|
107
|
|
|
respone_msg = ("The admins have received your report.\n" |
108
|
|
|
"They will investigation and may reach out") |
109
|
|
|
await utils.make_embed(ctx, title="Report Received", |
110
|
|
|
description=respone_msg) |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
def setup(bot): |
114
|
|
|
"""Needed for extension loading""" |
115
|
|
|
bot.add_cog(MiscCog(bot)) |
116
|
|
|
|