-
Notifications
You must be signed in to change notification settings - Fork 0
/
marriage.py
377 lines (348 loc) · 15.4 KB
/
marriage.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
import discord
import asyncio
from discord.ext import commands
import urllib.request
import json
import random
import pymysql
import os
class Marriage:
def __init__(self, client):
self.client = client
def is_owner(self, user):
if user.id == "164068466129633280" or user.id == "142002197998206976" or user.id == "457516809940107264":
return True
else:
return False
def check_setting(self, server, setting):
settingspath = "servers/{}/settings.json".format(server.id)
if not setting in open(settingspath, "r").read():
print("No such setting found")
return None
with open(settingspath, "r") as f:
json_data = json.load(f)
if json_data[setting] == 1:
return True
elif json_data[setting] == 0:
return False
else:
return json_data[setting]
@commands.command(pass_context=True)
async def marriage(self, ctx, user: discord.Member = None):
author = ctx.message.author
server = author.server
marriage_toggle = self.check_setting(server, "Marriage_Toggle")
if marriage_toggle == False:
embed = discord.Embed(
description="Marriage is currently disabled",
color=0xFF0000
)
await self.client.say(embed=embed)
return
conn = pymysql.connect(host="sql7.freesqldatabase.com", user="sql7273467", password="ihireg57sU", db="sql7273467")
c = conn.cursor()
if user == None:
sql = "SELECT * FROM `Marriage_Table` WHERE user1 = '{}' OR user2 = '{}'".format(str(author.id), str(author.id))
c.execute(sql)
conn.commit()
data = c.fetchall()
if len(data) >= 1:
for d in data:
user1 = d[1]
user2 = d[2]
if user1 == str(author.id):
married_to = int(user2)
else:
married_to = int(user1)
embed = discord.Embed(
description="You are married to <@{}>".format(married_to),
color=0xFF0000
)
embed.set_image(url="https://cdn.pixabay.com/photo/2015/12/11/17/28/heart-1088487_960_720.png")
await self.client.say(embed=embed)
else:
if author.id == "164068466129633280":
embed = discord.Embed(
description="You are married to **Charlotte Izoard**",
color=0xFF0000
)
embed.set_image(url="https://i.imgur.com/G7oJSjE.jpg")
await self.client.say(embed=embed)
return
elif author.id == "142002197998206976":
embed = discord.Embed(
description="You are married to **Yukana Yame**",
color=0xFF0000
)
embed.set_image(url="https://i.imgur.com/MEldWsb.jpg")
await self.client.say(embed=embed)
return
embed = discord.Embed(
description="You are not married",
color=0xFF0000
)
await self.client.say(embed=embed)
conn.close()
else:
sql = "SELECT * FROM `Marriage_Table` WHERE user1 = '{}' OR user2 = '{}'".format(str(user.id), str(user.id))
c.execute(sql)
conn.commit()
data = c.fetchall()
if len(data) >= 1:
for d in data:
user1 = d[1]
user2 = d[2]
if user1 == str(user.id):
married_to = int(user2)
else:
married_to = int(user1)
embed = discord.Embed(
description="{} is married to <@{}>".format(user.mention, married_to),
color=0xFF0000
)
embed.set_image(url="https://cdn.pixabay.com/photo/2015/12/11/17/28/heart-1088487_960_720.png")
await self.client.say(embed=embed)
else:
if user.id == "164068466129633280":
embed = discord.Embed(
description="You are married to **Charlotte Izoard**",
color=0xFF0000
)
embed.set_image(url="https://i.imgur.com/G7oJSjE.jpg")
await self.client.say(embed=embed)
return
elif user.id == "142002197998206976":
embed = discord.Embed(
description="You are married to **Yukana Yame**",
color=0xFF0000
)
embed.set_image(url="https://i.imgur.com/MEldWsb.jpg")
await self.client.say(embed=embed)
return
embed = discord.Embed(
description="{} is not married".format(user.mention),
color=0xFF0000
)
await self.client.say(embed=embed)
@commands.command(pass_context=True)
async def divorce(self, ctx):
author = ctx.message.author
server = ctx.message.server
channel = ctx.message.channel
marriage_toggle = self.check_setting(server, "Marriage_Toggle")
if marriage_toggle == False:
embed = discord.Embed(
description="Marriage is currently disabled",
color=0xFF0000
)
await self.client.say(embed=embed)
return
conn = pymysql.connect(host="sql7.freesqldatabase.com", user="sql7273467", password="ihireg57sU", db="sql7273467")
c = conn.cursor()
sql = "SELECT * FROM `Marriage_Table` WHERE user1 = '{}' OR user2 = '{}'".format(str(author.id), str(author.id))
c.execute(sql)
conn.commit()
data = c.fetchall()
if len(data) >= 1:
embed = discord.Embed(
description="Are you sure you wish to divorce?",
color=0xFF0000
)
await self.client.say(embed=embed)
user_response = await self.client.wait_for_message(timeout=40, channel=channel, author=author)
user_response = user_response.clean_content.lower()
if user_response == "yes":
for d in data:
roleid = d[4]
for srv in self.client.servers:
for role in list(srv.roles):
if str(role.id) == str(roleid):
try:
await self.client.delete_role(srv, role)
except discord.HTTPException:
embed = discord.Embed(
description = "Role doesn't exist in {}".format(srv.name),
color = 0xFF0000
)
await self.client.say(embed=embed)
sql = "DELETE FROM `Marriage_Table` WHERE user1 = '{}' OR user2 = '{}'".format(str(author.id), str(author.id))
c.execute(sql)
conn.commit()
embed = discord.Embed(
description="You broke up, you are now single",
color=0xFF0000
)
embed.set_image(url="https://upload.wikimedia.org/wikipedia/commons/b/bb/Broken_heart.svg")
await self.client.say(embed=embed)
elif user_response == "no":
embed = discord.Embed(
description="Good choice",
color=0xFF0000
)
await self.client.say(embed=embed)
else:
embed = discord.Embed(
description="Invalid response",
color=0xFF0000
)
await self.client.say(embed=embed)
else:
embed = discord.Embed(
description="You are not married",
color=0xFF0000
)
await self.client.say(embed=embed)
@commands.command(pass_context=True)
async def forcebreakup(self, ctx, user: discord.Member = None):
author = ctx.message.author
if self.is_owner(author):
if user == None:
embed = discord.Embed(
description="You have not tagged any user",
color=0xFF0000
)
await self.client.say(embed=embed)
return
else:
#breakup
conn = pymysql.connect(host="sql7.freesqldatabase.com", user="sql7273467", password="ihireg57sU", db="sql7273467")
c = conn.cursor()
sql = "SELECT * FROM `Marriage_Table` WHERE user1 = '{}' OR user2 = '{}'".format(str(user.id), str(user.id))
c.execute(sql)
conn.commit()
data = c.fetchall()
if len(data) >= 1:
sql = "DELETE FROM `Marriage_Table` WHERE user1 = '{}' OR user2 = '{}'".format(str(user.id), str(user.id))
c.execute(sql)
conn.commit()
for d in data:
roleid = d[4]
for srv in self.client.servers:
for role in list(srv.roles):
if str(role.id) == str(roleid):
try:
await self.client.delete_role(srv, role)
except discord.HTTPException:
embed = discord.Embed(
description = "Role doesn't exist in {}".format(srv.name),
color = 0xFF0000
)
await self.client.say(embed=embed)
embed = discord.Embed(
description="You have successfully forced a break up on {}".format(user.mention),
color=0xFF0000
)
await self.client.say(embed=embed)
else:
embed = discord.Embed(
description="This user is not married",
color=0xFF0000
)
await self.client.say(embed=embed)
conn.close()
else:
embed = discord.Embed(
description="You don't have permission to use this command",
color=0xFF0000
)
await self.client.say(embed=embed)
@commands.command(pass_context=True)
async def propose(self, ctx, user: discord.Member = None):
author = ctx.message.author
server = ctx.message.server
channel = ctx.message.channel
marriage_toggle = self.check_setting(server, "Marriage_Toggle")
if marriage_toggle == False:
embed = discord.Embed(
description="Marriage is currently disabled",
color=0xFF0000
)
await self.client.say(embed=embed)
return
if user == None:
embed = discord.Embed(
description="You have not tagged anyone",
color=0xFF0000
)
await self.client.say(embed=embed)
return
elif user == author:
embed = discord.Embed(
description="You can't marry yourself",
color=0xFF0000
)
await self.client.say(embed=embed)
return
conn = pymysql.connect(host="sql7.freesqldatabase.com", user="sql7273467", password="ihireg57sU", db="sql7273467")
c = conn.cursor()
sql = "SELECT * FROM `Marriage_Table` WHERE user1 = '{}' OR user2 = '{}'".format(str(author.id), str(author.id))
c.execute(sql)
conn.commit()
data = c.fetchall()
if len(data) >= 1:
embed = discord.Embed(
description="You are already married",
color=0xFF0000
)
await self.client.say(embed=embed)
return
else:
sql = "SELECT * FROM `Marriage_Table` WHERE user1 = '{}' OR user2 = '{}'".format(str(user.id), str(user.id))
c.execute(sql)
conn.commit()
data = c.fetchall()
if len(data) >= 1:
embed = discord.Embed(
description="{} is already married".format(user.mention),
color=0xFF0000
)
await self.client.say(embed=embed)
return
embed = discord.Embed(
title="Marriage",
description=":heart: {} is proposing to you, will you accept {}? :heart:".format(author.mention, user.mention),
color=0x330000
)
embed.set_image(url=author.avatar_url)
await self.client.say("{}".format(user.mention))
await self.client.say(embed=embed)
user_response = await self.client.wait_for_message(timeout=40, channel=channel, author=user)
user_response = user_response.clean_content.lower()
if user_response == "yes":
try:
rolename = "{} X {}".format(author.name, user.name)
createdrole = await self.client.create_role(server=server, name=rolename, color=discord.Color.purple())
sql = "INSERT INTO `Marriage_Table` (user1, user2, ring, roleid) VALUES ('{}', '{}', '{}', '{}')".format(str(author.id), str(user.id), "default", createdrole.id)
c.execute(sql)
conn.commit()
await self.client.add_roles(author, createdrole)
await self.client.add_roles(user, createdrole)
embed = discord.Embed(
title="Marriage",
description=":heart: {} and {} is now married :heart:".format(author.mention, user.mention),
color=0x330000
)
embed.set_image(url="https://cdn.pixabay.com/photo/2015/12/11/17/28/heart-1088487_960_720.png")
await self.client.say(embed=embed)
except discord.Forbidden:
embed = discord.Embed(
description = "Missing permissions",
color = 0xFF0000
)
await self.client.say(embed=embed)
elif user_response == "no":
embed = discord.Embed(
description="{} sadly denied your request to marry you :(".format(user.mention),
color=0xFF0000
)
await self.client.say(embed=embed)
return
else:
embed = discord.Embed(
description="Invalid response",
color=0xFF0000
)
await self.client.say(embed=embed)
conn.close()
def setup(client):
client.add_cog(Marriage(client))