-
Notifications
You must be signed in to change notification settings - Fork 0
/
Discord_Big_Bot.py
287 lines (237 loc) · 10.5 KB
/
Discord_Big_Bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import asyncio
import random
from datetime import *
import discord
from discord.ext import commands
import os
import Botkeys
try:
os.mkdir("logs")
except FileExistsError:
pass
try:
os.mkdir("transfers")
except FileExistsError:
pass
intents = discord.Intents.all()
intents.members = True
client = commands.Bot(command_prefix='Kevin ', intents=intents)
botkeys = Botkeys.get_keys()
async def load():
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
await client.load_extension(f'cogs.{filename[:-3]}')
async def main():
await load()
await client.start(botkeys["BotToken"])
def time():
now = datetime.now()
return now.strftime("[%H:%M:%S] --- ")
def logger(message):
os.chdir("logs")
today = date.today()
logfile = open(today.strftime("%Y%m%d") + ".txt", 'a', encoding='utf-8')
logfile.write("\n" + time() + message)
logfile.close()
os.chdir("..")
class Buttons(discord.ui.View):
def __init__(self, timeout=1800):
super().__init__(timeout=timeout)
@discord.ui.button(label="Redo", custom_id="teamsRedoButton", style=discord.ButtonStyle.blurple, emoji="🔄")
async def teams_redo_button(self, interaction: discord.Interaction, button: discord.ui.Button):
lines = interaction.message.content.split("\n")
team_num = len(lines)
members = []
for line in lines:
line = line[line.find(":")+2:]
for entry in line.split():
members.append(entry)
await interaction.message.edit(view=None)
await interaction.response.send_message(content=teams_comm(team_num, " ".join(members)), view=self)
@client.event
async def on_ready():
await client.change_presence(activity=discord.Activity(name="'Kevin help' for help.", type=3))
logger("Big Bot is online.")
print("Big Bot is online.")
@client.event
async def on_command_error(ctx, error):
if isinstance(error, discord.ext.commands.MissingRequiredArgument):
msg = f"Missing required argument(s): {error.param}\nI suggest you do `Kevin help {ctx.command}`"
elif isinstance(error, discord.ext.commands.MissingPermissions):
msg = f"Missing permissions: {error.missing_perms}."
elif isinstance(error, discord.ext.commands.CommandNotFound):
msg = f"No such command\nI suggest you do `Kevin help`"
elif isinstance(error, discord.ext.commands.MemberNotFound):
msg = f"Member {error.argument} does not exist."
elif isinstance(error, discord.ext.commands.CommandOnCooldown):
msg = "Command is on cooldown, give it {:.1f} seconds.".format(error.retry_after)
else:
msg = f"Something went wrong, or invalid input.\nI suggest you do `Kevin help {ctx.command}`\n{error}"
print(error)
logger("Error: " + str(error))
await ctx.send(msg)
@client.command(description="Replys with the time taken to respond in ms.")
async def ping(ctx):
latency = round(client.latency * 1000)
await ctx.send(f"Pong {latency}ms")
logger("Ping command, with latency:" + str(latency))
@client.command(description="Repeats whatever you wrote.")
async def say(ctx, *, message):
await ctx.send(message)
logger("From: " + ctx.message.author.name + "\nSaid: " + message)
@client.command(aliases=['8ball'], description="Gives you an 8ball reply.")
async def _8ball(ctx, *, question):
responses = ["It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes – definitely.",
"You may rely on it.",
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful."]
reply = random.choice(responses)
await ctx.send(reply)
logger("8Ball result: " + reply)
@client.command(aliases=['coin', 'headsortails', 'heads', 'tails'], description="Flips a coin.")
async def coinflip(ctx):
results = ["Heads.", "Tails."]
reply = random.choice(results)
await ctx.send(reply)
logger("Heads or tails, result: " + reply)
@commands.has_permissions(manage_messages=True)
@client.command(aliases=['prune'], description="Deletes the most recent messages. The number does not count the messag"
"e itself.")
async def clear(ctx, amount=0):
await ctx.channel.purge(limit=amount + 1)
logger("Clearing " + str(amount) + " lines.")
@client.command(description="Warns a user.")
async def warn(ctx, member: discord.Member):
msg = "You have 2 weeks."
await member.send(msg)
logger("Warning: " + str(member))
@client.command(aliases=['pm', 'msg', 'whisper', 'message'], description="The bot will send a message to the given user"
". EG: Kevin dm @Shrewd#3618 testing message")
async def dm(ctx, member: discord.Member, *, message):
await member.send(message)
logger("Sending message to: " + str(member) + ". The message: " + message)
@client.command(aliases=['Paint', 'assign'],
description="Gives a user another user in the group, with no repeats. "
"Separate names with only a single space.")
async def paint(ctx, *, memberlist):
logger("Paint command received, string: " + memberlist)
members = memberlist.split(" ")
if len(members) == 1:
await ctx.send("Not enough members provided.")
logger("Not enough members provided for paint command.")
return
logger("Provided members: " + str(members))
while True:
reset = 0
results = []
used = []
for x in range(0, len(members)):
choice = random.choice(members)
while members[x] == choice or choice in used:
choice = random.choice(members)
if len(used) == len(members) - 1 and members[x] == choice:
reset = 1
break
results.append(members[x] + " --> ||" + choice + "||")
used.append(choice)
if reset == 0:
break
logstr = "\n ------Results------"
for x in results:
await ctx.send(x)
logstr += "\n " + x
logger(logstr)
def teams_comm(amount, members):
logger("Teams: String received: " + members)
results = []
amount = int(amount)
members = members.split(" ")
i = 0
while i < amount:
results.append("")
i += 1
while members:
for i in range(0, amount):
results[i] += members.pop(random.randint(0, len(members)-1)) + " "
if not members:
break
logstr = "\n ------Results------"
msg = ""
for x in range(0, len(results)):
msg += "Team number " + str(x + 1) + ": " + results[x] + "\n"
logstr += "\n " + "Team number " + str(x + 1) + ": " + results[x]
logger(logstr)
return msg
@client.command(aliases=['team', 'split', 'Team', 'Teams', 'Split'],
description="Splits given people into given number of teams. Separate names with only a single space.")
async def teams(ctx, amount, *, memberlist):
await ctx.send(teams_comm(amount, memberlist), view=Buttons())
@client.command(aliases=['pick'], description="Chooses an item in a given set of items. Separate names with a single"
" space.")
async def choose(ctx, *, itemlist):
logger("Choose: String received: " + itemlist)
items = itemlist.split(" ")
logger("Items: " + str(items))
result = random.choice(items)
logger("Chosen item: " + result)
await ctx.send("I choose " + result + ".")
@client.command(description="Returns a random fact.")
async def fact(ctx):
facts = open("facts.txt", "r+").readlines()
await ctx.send("Did you know: " + random.choice(facts)[:-1])
logger("A real fact was printed.")
@client.command(description="Holds a poll with reactions. Prompt comes first, then separate the prompt and options with"
" a comma - Kevin poll This is a prompt, opt1, opt2, opt3")
async def poll(ctx, *, question):
options = question.split(",")
prompt = options.pop(0)
number_emojis = ["1\N{combining enclosing keycap}", "2\N{combining enclosing keycap}",
"3\N{combining enclosing keycap}", "4\N{combining enclosing keycap}",
"5\N{combining enclosing keycap}", "6\N{combining enclosing keycap}",
"7\N{combining enclosing keycap}", "8\N{combining enclosing keycap}",
"9\N{combining enclosing keycap}", "0\N{combining enclosing keycap}"]
options_str = ""
for i in range(0, len(options)):
options[i] = number_emojis[i] + options[i] + "\n"
options_str += options[i]
msg = await ctx.send(prompt + "\n" + options_str)
logger("Poll called with prompt: " + prompt + ", and options: " + str(options))
for i in range(0, len(options)):
await msg.add_reaction(number_emojis[i])
@client.command(description="Wishes luck to kevin")
async def goodluck(ctx, *rest):
await ctx.send("Thanks.")
@client.command(description="Retrives a given amount (max 10) of random screenshot from lightshot's website, prnt.sc\n "
"Warning: These are really random, you might see things that you shouldn't or wouldn't want"
" to.")
async def randomss(ctx, amount: int = 1):
if amount < 1:
amount = 1
elif amount > 5:
amount = 5
alphanumeric = "1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z"
alpha = alphanumeric.split(" ")
result = ""
for i in range(0, amount):
page = "https://prnt.sc/"
for j in range(6):
page += random.choice(alpha)
result += page + "\n"
await ctx.send(result)
asyncio.run(main())