-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtruthordare.py
325 lines (289 loc) · 11.7 KB
/
truthordare.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
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
import random
import sqlite3
import discord
from discord.ext import commands
from discord.ui import Button, View
betaservers = [
908963077125459989,
401041820458680340,
985655459576959078,
1010679471109574667,
]
# Somewhere (in the check func)
def enabled_check(ctx):
con = sqlite3.connect("databases/truthordare.db")
cur = con.cursor()
cur.execute(f"SELECT toggel FROM truthordare WHERE server_id = {ctx.guild.id}")
result = cur.fetchone()
if result[0] == 1:
return True
else:
return False
def get_truth(interaction):
with open("databases/truth.txt", "r") as f:
lines = f.readlines()
text = random.choice(lines)
text = text.replace(
"{{randomly_selected_userer}}",
f"{random.choice(interaction.guild.members).display_name}",
)
embed = discord.Embed(title="Truth", description=text, color=0x00FF00)
embed.set_footer(text=f"Requested by {interaction.user.name}")
return embed
def get_dare(interaction):
with open("databases/dare.txt", "r") as f:
lines = f.readlines()
text = random.choice(lines)
text = text.replace(
"{{randomly_selected_userer}}",
f"{random.choice(interaction.guild.members).display_name}",
)
embed = discord.Embed(title="Dare", description=text, color=0xFF0000)
embed.set_footer(text=f"Requested by {interaction.user.name}")
return embed
def get_random_truthordare(interaction):
random_number = random.randint(1, 2)
if random_number == 1:
return get_truth(interaction)
else:
return get_dare(interaction)
class TruthOrDare(commands.Cog):
"""All the commands needed to set up truth or dare"""
def __init__(self, client):
self.client = client
# @commands.command(hidden=True)
# @commands.is_owner()
# async def maketable(self, ctx):
# con = sqlite3.connect('databases/truthordare.db')
# cur = con.cursor()
# cur.execute("CREATE table truthordare (server_id int, toggel int)")
# con.commit()
# con.close()
# await ctx.send("Table created")
# for i in self.client.guilds:
# con = sqlite3.connect('databases/truthordare.db')
# cur = con.cursor()
# cur.execute("INSERT INTO truthordare VALUES (?, ?)", (i.id, 0))
# con.commit()
# con.close()
# await ctx.send("Table filled")
# onserverjoin
@commands.Cog.listener()
async def on_guild_join(self, guild):
con = sqlite3.connect("databases/truthordare.db")
cur = con.cursor()
data = cur.execute("SELECT * FROM truthordare WHERE server_id = ?", (guild.id,))
data = data.fetchall()
if len(data) == 0:
cur.execute("INSERT INTO truthordare VALUES (?, ?)", (guild.id, 0))
con.commit()
con.close()
else:
pass
@commands.slash_command(
name="toggle_truthordare", description="Toggle truth or dare"
)
@commands.has_permissions(administrator=True)
async def truthordare_toggle(self, ctx):
con = sqlite3.connect("databases/truthordare.db")
cur = con.cursor()
data = cur.execute(
"SELECT toggel FROM truthordare WHERE server_id = ?", (ctx.guild.id,)
)
data = data.fetchall()
# check if there is a row for the server
if len(data):
if data[0][0] == 0:
cur.execute(
"UPDATE truthordare SET toggel = ? WHERE server_id = ?",
(1, ctx.guild.id),
)
con.commit()
con.close()
await ctx.respond("Truth or dare enabled!")
else:
cur.execute(
"UPDATE truthordare SET toggel = ? WHERE server_id = ?",
(0, ctx.guild.id),
)
con.commit()
con.close()
await ctx.respond("Truth or dare disabled!")
else:
cur.execute("INSERT INTO truthordare VALUES (?, ?)", (ctx.guild.id, 1))
con.commit()
con.close()
await ctx.respond("Truth or dare enabled!")
await ctx.respond(
"Please feel free to vote for simplex and me. It would mean a lot to us and it helps load. https://top.gg/bot/902240397273743361",
ephemeral=True,
)
@commands.command()
@commands.is_owner()
async def maketruthordarefile(self, ctx):
open("databases/dare.txt", "w").close()
open("databases/truth.txt", "w").close()
truthfile = open("databases/truth.txt", "w")
darefile = open("databases/dare.txt", "w")
channel = self.client.get_channel(1031279120623083560)
messages = await channel.history(limit=None).flatten()
for i in messages:
truthfile.write(i.content + "\n")
truthfile.close()
channel = self.client.get_channel(1031279167360212993)
messages = await channel.history(limit=None).flatten()
for i in messages:
darefile.write(i.content + "\n")
darefile.close()
await ctx.send("Done")
@commands.slash_command(name="truth", description="Get a truth")
async def truth(self, ctx):
if enabled_check(ctx) == True:
truthbutton = Button(
label="Truth", style=discord.ButtonStyle.green, custom_id="truth"
)
darebutton = Button(
label="Dare", style=discord.ButtonStyle.red, custom_id="dare"
)
randombutton = Button(
label="Random", style=discord.ButtonStyle.blurple, custom_id="random"
)
linktoserver = Button(
label="Join our server",
style=discord.ButtonStyle.link,
url="https://discord.gg/w4ZbjyVQEr",
)
votebutton = Button(
label="Vote for us",
style=discord.ButtonStyle.link,
url="https://top.gg/bot/902240397273743361",
)
async def callback(interaction):
if interaction.data["custom_id"] == "truth":
await interaction.response.send_message(
embed=get_truth(interaction), view=view
)
elif interaction.data["custom_id"] == "dare":
await interaction.response.send_message(
embed=get_dare(interaction), view=view
)
elif interaction.data["custom_id"] == "random":
await interaction.response.send_message(
embed=get_random_truthordare(interaction), view=view
)
truthbutton.callback = callback
darebutton.callback = callback
randombutton.callback = callback
view = View(timeout=None)
view.add_item(truthbutton)
view.add_item(darebutton)
view.add_item(randombutton)
if random.randint(0, 15) == 10:
view.add_item(linktoserver)
if random.randint(0, 15) == 15:
view.add_item(votebutton)
await ctx.respond(embed=get_truth(ctx), view=view)
else:
await ctx.respond("Truth or dare is disabled on this server")
@commands.slash_command(name="dare", description="Get a dare")
async def dare(self, ctx):
if enabled_check(ctx) == True:
truthbutton = Button(
label="Truth", style=discord.ButtonStyle.green, custom_id="truth"
)
darebutton = Button(
label="Dare", style=discord.ButtonStyle.red, custom_id="dare"
)
randombutton = Button(
label="Random", style=discord.ButtonStyle.blurple, custom_id="random"
)
linktoserver = Button(
label="Join our server",
style=discord.ButtonStyle.link,
url="https://discord.gg/w4ZbjyVQEr",
)
votebutton = Button(
label="Vote for us",
style=discord.ButtonStyle.link,
url="https://top.gg/bot/902240397273743361",
)
async def callback(interaction):
if interaction.data["custom_id"] == "truth":
await interaction.response.send_message(
embed=get_truth(interaction), view=view
)
elif interaction.data["custom_id"] == "dare":
await interaction.response.send_message(
embed=get_dare(interaction), view=view
)
elif interaction.data["custom_id"] == "random":
await interaction.response.send_message(
embed=get_random_truthordare(interaction), view=view
)
truthbutton.callback = callback
darebutton.callback = callback
randombutton.callback = callback
view = View(timeout=None)
view.add_item(truthbutton)
view.add_item(darebutton)
view.add_item(randombutton)
if random.randint(0, 15) == 10:
view.add_item(linktoserver)
if random.randint(0, 15) == 15:
view.add_item(votebutton)
await ctx.respond(embed=get_dare(ctx), view=view)
else:
await ctx.respond("Truth or dare is disabled on this server")
@commands.slash_command(
name="truthordare", description="Get a truth or a dare", pass_context=True
)
async def truthordare(self, ctx):
if enabled_check(ctx) == True:
truthbutton = Button(
label="Truth", style=discord.ButtonStyle.green, custom_id="truth"
)
darebutton = Button(
label="Dare", style=discord.ButtonStyle.red, custom_id="dare"
)
randombutton = Button(
label="Random", style=discord.ButtonStyle.blurple, custom_id="random"
)
linktoserver = Button(
label="Join our server",
style=discord.ButtonStyle.link,
url="https://discord.gg/w4ZbjyVQEr",
)
votebutton = Button(
label="Vote for us",
style=discord.ButtonStyle.link,
url="https://top.gg/bot/902240397273743361",
)
async def callback(interaction):
if interaction.data["custom_id"] == "truth":
await interaction.response.send_message(
embed=get_truth(interaction), view=view
)
elif interaction.data["custom_id"] == "dare":
await interaction.response.send_message(
embed=get_dare(interaction), view=view
)
elif interaction.data["custom_id"] == "random":
await interaction.response.send_message(
embed=get_random_truthordare(interaction), view=view
)
truthbutton.callback = callback
darebutton.callback = callback
randombutton.callback = callback
view = View(timeout=None)
view.add_item(truthbutton)
view.add_item(darebutton)
view.add_item(randombutton)
if random.randint(0, 15) == 10:
view.add_item(linktoserver)
if random.randint(0, 15) == 15:
view.add_item(votebutton)
await ctx.respond(embed=get_random_truthordare(ctx), view=view)
else:
await ctx.respond("Truth or dare is disabled on this server")
def setup(client):
client.add_cog(TruthOrDare(client))