-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
337 lines (259 loc) · 12.9 KB
/
main.py
File metadata and controls
337 lines (259 loc) · 12.9 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import discord
from discord.ext import commands
import os
import asyncio
from asyncio import sleep
import random
import aiosqlite
import typing
import datetime
prefix = "prefix u have"
bot = commands.Bot(command_prefix=prefix,intents=discord.Intents.all(), case_insensitive=True)
#bot.remove_command('help') <- if u want
db = aiosqlite.connect("main.sqlite")
@bot.event
async def on_ready():
await db
cursor = await db.cursor()
await cursor.execute("""
CREATE TABLE IF NOT EXISTS blacklist(
guild_id INTEGER,
user_id INTEGER,
blacklisted BOOL
)""")
await db.commit()
# await cursor.execute("""
# CREATE TABLE IF NOT EXISTS giveaway(
# user_id INTEGER,
# channel_id INTEGER,
# guild_id INTEGER,
# winners INTEGER,
# time TEXT NOT NULL,
# prize TEXT NOT NULL
# )""")
print(f'Logged in as {bot.user}\n{bot.user.id}')
await status()
async def status():
while True:
await bot.wait_until_ready()
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f'{len(bot.guilds)} servers! '))
await sleep(40)
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f'my prefix {prefix}'))
await sleep(15)
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"{len(bot.commands)} commands"))
await sleep(15) # make it anything u want
async def GetMessage(
bot, ctx, contentOne = "Default message", contentTwo = "\uFEFF", timeout = 100
):
embed = discord.Embed(title = f"{contentOne}", description=f"{contentTwo}")
sent = await ctx.send(embed=embed)
try:
msg = await bot.wait_for("message", timeout=timeout, check = lambda message: message.author == ctx.author and message.channel == ctx.channel,
)
if msg:
return msg.content
except asyncio.TimeoutError:
return False # got this code from camberra, it will be modified.
@bot.command()
async def gstart(ctx, mins : int, * , prize: str, winners: int=1):
embed = discord.Embed(title = "Giveaway!", description = f"{prize}", color = ctx.author.color)
end = datetime.datetime.utcnow() + datetime.timedelta(seconds = mins*60)
start = datetime.datetime.utcnow()
print(end)
print(start)
winner = []
embed.add_field(name = "Ends At:", value = f"{end} UTC! \n{winners} winners!!")
embed.set_footer(text = f"Ends {mins} minutes from now! Will start counting down by 30 seconds") # <- You can change to whatever time you want.
my_msg = await ctx.send(embed = embed)
await my_msg.add_reaction("EMOJI") # fill in emoji here
while True:
difference = end - datetime.datetime.now()
count_hours, rem = divmod(difference.seconds, 3600)
count_minutes, count_seconds = divmod(rem, 60)
if difference.days == 0 and count_hours == 0 and count_minutes == 0 and count_seconds == 0:
new_msg = await ctx.channel.fetch_message(my_msg.id)
try:
users = await new_msg.reactions[0].users().flatten()
users.pop(users.index(self.bot.user))
for x in range(winners):
winner.append(random.choice(users))
# winner = random.choice(users)
except IndexError:
return await ctx.send("no one chose in time") # didn't feel like raising it
await ctx.send("Congratulations! {} won {}!".format(", ".join([users.mention for users in winner]), prize))
break
if count_seconds <= 30:
embed = discord.Embed(title = "Giveaway!", description = f"{prize}", color = ctx.author.color)
embed.add_field(name = "Ends At:", value = f"{end} UTC")
embed.set_footer(text = f"Ends {count_seconds} seconds from now!") # you could put mins thne change it to seconds Idc
await my_msg.edit(embed=embed)
# print('The count is: '
# + str(difference.days) + " day(s) "
# + str(count_hours) + " hour(s) "
# + str(count_minutes) + " minute(s) "
# + str(count_seconds) + " second(s) "
# )
time.sleep(1)
@bot.command()
async def giveaway(ctx):
await ctx.send("Ok we will run giveaway, now simply answer the questions **below**.")
questionlist = [
["In which channel should the giveaway be in?", "Mention it!"],
["How long should this giveaway be?", "**AND AGAIN** use `s|m|h|d` ."],
["What is the prize of this giveaway?", "BE ***HUMBLE***."]
]
answers = {}
for i, question in enumerate(questionlist):
answer = await GetMessage(bot, ctx, question[0], question[1])
if not answer:
await ctx.send("Oyy, give me an answer. ***BRUH***")
answers[i] = answer
em = discord.Embed(title="Giveaway questions", color = discord.Color.orange())
for key, value in answers.items():
em.add_field(name = f"Question {questionlist[key][0]}", value=f"Answer: `{value}`", inline=False)
m = await ctx.send("Are these all valid? Gimme answer!", embed=em)
await m.add_reaction("✅")
await m.add_reaction("❌")
try:
reaction, member = await bot.wait_for('reaction_add', timeout=45, check = lambda reaction, user: user == ctx.author and reaction.message.channel == ctx.channel)
except asyncio.TimeoutError:
await ctx.send("You took too much. Sorry!")
return
if str(reaction.emoji) not in ["✅", "❌"] or str(reaction.emoji) == "❌":
await ctx.send("Giveaway canceled!")
channelid = re.findall(r"[0-9]+", answers[0])[0]
channel = self.bot.get_channel(int(channelid))
time = convert(answers[1])
em = discord.Embed(title="**GIVEAWAY**", description=f" **Prize** : {answers[2]}\n **Time** : {time}\n **Winners** : 1", color = discord.Color.orange())
em.set_footer(text= f"Holden by {ctx.author.name}.")
em.set_thumbnail(url = 'https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/mozilla/36/party-popper_1f389.png')
message = await channel.send(embed=em)
await message.add_reaction("EMOJI u want")
await asyncio.sleep(time)
message = await channel.fetch_message(message.id)
users = await message.reactions[0].users().flatten()
users.pop(users.index(ctx.guild.me))
if len(users) == None:
await channel.send("There was no winner! *Sucks*.")
winner = random.choice(users)
await channel.send(f"**Congrats** {winner.mention}!**\n Message him {ctx.author.mention} to get your beloved prize.")
blacklist = set() # to blacklsit users
@bot.command(name="blacklist")
async def _blacklist(ctx, mode, target: discord.Member = None, *, reason=None):
"""Owner Command, will blacklist a user from bot"""
cursor = await db.cursor()
if target == None:
return await ctx.send("Bruh mention someone") # if you want to blacklsit roles jsut do this same code, for giveaways ofc, and change the param to discord.Role and create a new table
await cursor.execute("SELECT user_id FROM blacklist WHERE user_id=?", (target.id,))
row = await cursor.fetchone()
if not row:
await cursor.execute("INSERT INTO blacklist(guild_id, user_id, blacklisted) VALUES(?, ?, ?)", (ctx.guild.id, target.id, False, ))
# if target.id == ctx.author.id:
# return await ctx.send("Dont blacklist yourself idiot")
if mode != "remove" and mode != "add":
return await ctx.send("Mate, it has to be add or remove")
blacklists = True if mode == "add" else False
await cursor.execute("UPDATE blacklist SET blacklisted = ? WHERE user_id = ? AND guild_id=?", (blacklists, target.id, ctx.guild.id))
await db.commit()
if mode == "add":
em = discord.Embed(title="Man got blacklisted", description="Now you can't use bot you noob", color = discord.Color.red())
em.add_field(name="Reason", value=reason or "None specified")
await target.send(embed=em)
await ctx.send(f"Succesfully blacklisted {target.name}")
blacklist.add(target.id)
# print(blacklist)
else:
await ctx.send(f"{target.name} is unblacklsited YAY!!!!")
try:
blacklist.remove(target.id)
print(blacklist)
except KeyError:
return await ctx.send(f"Cant remove {target.name}")
@bot.command()
async def blacklisted(ctx):
cursor = await db.cursor()
await cursor.execute("SELECT * FROM blacklist WHERE guild_id=? AND blacklisted=?", (ctx.guild.id, True,))
row = await cursor.fetchall()
print(row)
@bot.event
async def on_message(message):
if message.author.id in blacklist: # had to do in main file too lazy to do all the cog work since it would cause so many problems
return
await bot.process_commands(message)
@bot.command()
async def fight(ctx, member:discord.Member = None):# my code for people who want dank meme fight cmd
health = {
ctx.author: 100,
member: 100
}
if ctx.author == member:
await ctx.send("LEL, You seriously wanna beat the hell out of yourself, but **__NO__**.")
return
if member == None:
await ctx.send("You aren't an airbender to fight with air, so choose an opponent.")
return
# if rank(ctx, member) < 10:
# await ctx.send("**You need to be lvl 10 or higher!**")
# return
# this if statement is only if u have the lvl code DO NOT USE
option_1 = "punch"
option_2 = "defend"
option_3 = "end"
damage = random.randint(1, 40)
defend = random.randint(1, 40)
em = discord.Embed(color=member.color)
em.set_author(name=f"Peace was **never** an option. Now you are fighting {member}!")
em.add_field(name="Options", value=f"{member.mention} what do u want to do: \n `{option_1}` `{option_2}` or `{option_3}`?", inline=False)
em.set_thumbnail(url=member.avatar_url)
await ctx.send(embed=em)
skip = False
players = [(ctx.author, member),(member,ctx.author)]
for defender, attacker in itertools.cycle(players):
if(skip):
skip = False
continue
try:
msg = await prompt_choice(ctx, attacker)
except asyncio.TimeoutError:
await ctx.send(f"**{attacker.mention}** is nothing more than a sucker, so he left!")
return
if msg.lower() == 'punch':
damage = random.randint(1, 40)
health[defender] -= damage
await ctx.send(f"Your serious punch just dealt {damage} damage and now {defender.mention} hp is at {health[defender]}!")
elif msg.lower() == 'defend':
heal = random.randint(1, 30)
if health[attacker] == 100:
await ctx.send("Oy, You are at your max kiddo, you can't heal anymore.")
await ctx.send(f"**{attacker.mention}, what will you do now? OPTIONS: `punch` `defend` or `end`**")
skip = True
continue
else:
health[attacker] += heal
if health[attacker] > 100:
health[attacker] = 100
await ctx.send(f"You just healed {heal} hp and now {attacker.mention} is at hp is at {health[attacker]}!")
elif msg.lower() == 'end':
await ctx.send("**You ran away, your opponent wins scrub!**")
return
else:
await ctx.send(f"{attacker.mention} did not enter a valid option!")
await ctx.send(f"**{attacker.mention}, what will you do now? OPTIONS: `punch`, `defend`, `end`**")
skip = True
continue
if health[attacker] <= 0:
if health[attacker] < 0:
health[attacker] = 0
await ctx.send(f"**{defender.mention}** has won. You are in for a treat.!")
break
elif health[defender] <= 0:
if health[defender] < 0:
health[defender] = 0
await ctx.send(f"**{attacker.mention}** won. You're in for a treat.!")
break
await ctx.send(f"**{defender.mention}, what will you do now? OPTIONS: `punch` `defend` `end`**")
async def prompt_choice(ctx: commands.Context, member: discord.Member) -> str: # now we need to import random...
valid_choices = ["bm", "sp", "sd", "mc", "all", "end"]
responses = await bot.wait_for('message', check = lambda m: all((m.author == member, m.channel == ctx.channel)), timeout=60)
return responses.content
bot.run(os.getenv('TOKEN'))