-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbotstart.py
executable file
·558 lines (493 loc) · 25.4 KB
/
botstart.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
#!/usr/bin/python3
import json
import os
import aiohttp
import aiofiles
import os.path
import subprocess
import re
import sqlite3
from pathlib import Path
import sys
import requests
import urllib.request
import discord
from discord.utils import get
from discord import Message, Member, Forbidden, Reaction, User, Role, Embed, Emoji
from discord.ext.commands import Bot, Context, UserConverter, CommandError, Converter
from requests import Response
global database
database = sqlite3.connect("db/database")
prefix = "."
resimcount = 0
#dersargumani çok kullanıldığı için on_message fonksiyonundan diğer fonksiyonlara geçirebiliriz direk.
bot = Bot(command_prefix=prefix)
@bot.event
async def on_ready():
init()
print("Yaşıyorum ^^")
print(bot.user.name + " olarak giriş yapıldı, id = " + bot.user.id)
@bot.event
async def on_message(message: Message):
global database
cursor = database.cursor()
user = f"'%{str(message.author)}%'"
if message.author == bot.user:
return
register(message)
if await image_download(message):
return
cursor.execute(f"SELECT acheck FROM users WHERE username LIKE {user}")
acheck = cursor.fetchone()[0]
cursor.execute(f"SELECT ncheck FROM users WHERE username LIKE {user}")
ncheck = cursor.fetchone()[0]
cursor.execute(f"SELECT dcheck FROM users WHERE username LIKE {user}")
dcheck = cursor.fetchone()[0]
if ncheck != "NULL":
return await get_note_image(message)
if acheck != "NULL":
return await get_answer_image(message)
if dcheck == "1": #TODO: kişiye özel olmalı
return await selectDers(message)
try:
if message.content[0] == prefix:
return await bot.process_commands(message)
except IndexError:
print("Yazısız mesaj!")
async def is_image(message: Message):
i = 0
if len(message.attachments) > 0:
while(i != len(message.attachments)):
if message.attachments[i]['filename'].split('.')[-1] in {'jpeg', 'png', 'jpg'}:
return True
else:
print(f"{message.author}: {message.content}")
await bot.send_message(message.channel, "Geçersiz dosya biçimi. Lütfen sadece fotoğraf dosyaları gönderin. " + message.author.mention)
return False
async def image_download(message: Message):
global database
cursor = database.cursor()
user = f"'%{str(message.author)}%'"
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
cursor.execute(f"SELECT acheck FROM users WHERE username LIKE {user}")
acheck = cursor.fetchone()[0]
cursor.execute(f"SELECT ncheck FROM users WHERE username LIKE {user}")
ncheck = cursor.fetchone()[0]
if dersargumani != "NULL" and acheck == "NULL" and ncheck == "NULL":
if await is_image(message):
i = 0
resimcount = len(message.attachments)
print(str(resimcount) + " soru var")
if not os.path.exists("db/" + str(message.author) + "/Çözülmemiş/" + dersargumani + "/"):
os.makedirs("db/" + str(message.author) + "/Çözülmemiş/" + dersargumani + "/")
file = await aiofiles.open("db/" + str(message.author) + "/Çözülmemiş/" + dersargumani + "/db", "a+")
await file.write("1")
await file.close()
while (i != resimcount):
file = await aiofiles.open("db/" + str(message.author) + "/Çözülmemiş/" + dersargumani + "/db", "r+")
sorucount = await file.readline()
print(sorucount)
url = message.attachments[i]['url']
print(url)
path = "db/" + str(message.author) + "/Çözülmemiş/" + dersargumani + "/" + dersargumani + sorucount + ".jpg"
await download_file(url, path)
file = await aiofiles.open("db/" + str(message.author) + "/Çözülmemiş/" + dersargumani + "/db", "w+")
if os.path.isfile(path):
await file.write(str(int(sorucount) + 1))
#TODO: Liste
await file.close()
else:
await bot.send_message(message.channel, "İndirme sırasında hata!" + message.author.mention)
await bot.send_message(message.channel, "Sorunuz " + dersargumani + sorucount + " adı ile kayıt edildi." + message.author.mention)
i = i + 1
return
if len(message.attachments) < 1:
print(f"{message.author}: {message.content}")
return
async def download_file(url, path):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
if resp.status == 200:
f = await aiofiles.open(path, mode='wb')
await f.write(await resp.read())
await f.close()
return
def register(message: Message):
global database
cursor = database.cursor()
user = f"'%{str(message.author)}%'"
cursor.execute(f"SELECT id, dcheck FROM users WHERE username LIKE {user}")
result = cursor.fetchone()
print('test')
if result is None:
print('test2')
cursor.execute('''INSERT INTO users(username, dcheck, acheck, ncheck, ders, sudo)
VALUES(?,?,?,?,?,?)''', (str(message.author), "0", "NULL", "NULL", "NULL", "0"))
database.commit()
if not os.path.exists("db/" + str(message.author)):
os.makedirs("db/" + str(message.author))
if not os.path.exists("db/" + str(message.author) + "/Çözülmemiş/"):
os.makedirs("db/" + str(message.author) + "/Çözülmemiş/")
if not os.path.exists("db/" + str(message.author) + "/Notlar/"):
os.makedirs("db/" + str(message.author) + "/Notlar/")
if not os.path.exists("db/" + str(message.author) + "/Çözülmüş/"):
os.makedirs("db/" + str(message.author) + "/Çözülmüş/")
def init():
if not os.path.exists("db"):
os.makedirs("db")
print("db klasörü oluşturuldu!")
global database
cursor = database.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, username TEXT,
dcheck TEXT, acheck TEXT, ncheck Text, ders TEXT, sudo TEXT)
''')
return
async def changeDers(message: Message, dersadi):
global database
cursor = database.cursor()
user = f"'%{str(message.author)}%'"
cursor.execute(f"UPDATE users SET ders = '{dersadi}' WHERE username LIKE {user}")
database.commit()
return await bot.send_message(message.channel, "Ders " + dersadi + " olarak ayarlandı. " + message.author.mention)
async def selectDers(message: Message):
global database
cursor = database.cursor()
user = f"'%{str(message.author)}%'"
if "0" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "NULL")
if "1" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Geometri")
if "2" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "MatematikTYT")
if "3" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "MatematikAYT")
if "4" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Fizik")
if "5" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Kimya")
if "6" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Biyoloji")
if "7" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Türkçe")
if "8" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Coğrafya")
if "9" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Felsefe")
if "10" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Tarih")
if "11" in message.content.split():
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await changeDers(message, "Din")
else:
return await bot.send_message(message.channel, "Lütfen listedeki derslerden birini giriniz")
return
@bot.command(pass_context=True)
async def s(ctx, *args):
if len(args) > 0:
i = 0
global database
cursor = database.cursor()
user = f"'%{str(ctx.message.author)}%'"
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
while(i != len(args)):
path = "db/" + str(ctx.message.author) + "/Çözülmemiş/" + dersargumani
if os.path.exists(path):
if len(str(args[i]).split('-')) == 2:
a = args[i].split('-')[0]
while (int(a) <= int(args[i].split('-')[1])):
if os.path.isfile(path + "/" + dersargumani + a + ".jpg"):
await bot.send_file(ctx.message.channel, path + "/" + dersargumani + a + ".jpg")
a = str(int(a) + 1)
else:
await bot.send_message(ctx.message.channel, dersargumani + a + " adında bir soru bulunamadı " + ctx.message.author.mention)
i = i + 1
if os.path.isfile(path + "/" + dersargumani + args[i] + ".jpg"):
await bot.send_file(ctx.message.channel, path + "/" + dersargumani + args[i] + ".jpg")
else:
await bot.send_message(ctx.message.channel, dersargumani + args[i] + " adında bir soru bulunamadı " + ctx.message.author.mention)
if os.path.isfile("db/" + str(ctx.message.author) + "/Çözülmüş/" + dersargumani + "/" + dersargumani + args[i] + ".jpg"):
await bot.send_file(ctx.message.channel, "db/" + str(ctx.message.author) + "/Çözülmüş/" + dersargumani + "/" + dersargumani + args[i] + ".jpg")
i = i + 1
else:
i = i + 1
await bot.send_message(ctx.message.channel, dersargumani + " dersine kayıtlı hiçbir soru yok." + ctx.message.author.mention)
else:
return await bot.send_message(ctx.message.channel, "Lütfen soru adı giriniz." + ctx.message.author.mention)
return
async def get_answer_image(message: Message):
global database
cursor = database.cursor()
user = f"'%{str(message.author)}%'"
if len(message.content) > 0:
if message.content[0] == "i": #TODO: i'yi küçültüp bak.
cursor.execute(f"UPDATE users SET acheck = 'NULL' WHERE username LIKE {user}")
database.commit()
await bot.send_message(message.channel, "İptal edildi." + message.author.mention)
return
if await is_image(message):
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
cursor.execute(f"SELECT acheck FROM users WHERE username LIKE {user}")
acheck = cursor.fetchone()[0]
if not os.path.exists("db/" + str(message.author) + "/Çözülmüş/" + dersargumani + "/"):
os.makedirs("db/" + str(message.author) + "/Çözülmüş/" + dersargumani + "/")
url = message.attachments[0]['url']
await download_file(url, "db/" + str(message.author) + "/Çözülmüş/" + dersargumani + "/" + acheck)
file = await aiofiles.open("db/" + str(message.author) + "/acheck", "w")
cursor.execute(f"UPDATE users SET acheck = 'NULL' WHERE username LIKE {user}")
database.commit()
return await bot.send_message(message.channel, "Çözümünüz " + acheck + " adı ile kayıt edildi." + message.author.mention)
else:
return await bot.send_message(message.channel, "Lütfen cevap fotoğrafını gönderin, iptal için iptal yazın." + message.author.mention)
return
async def get_note_image(message: Message):
global database
cursor = database.cursor()
user = f"'%{str(message.author)}%'"
if len(message.content) > 0:
if message.content[0].lower() == "i": #TODO: i'yi küçültüp bak.
await bot.send_message(message.channel, "İptal edildi." + message.author.mention)
cursor.execute(f"UPDATE users SET ncheck = 'NULL' WHERE username LIKE {user}")
database.commit()
return
if await is_image(message):
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
cursor.execute(f"SELECT ncheck FROM users WHERE username LIKE {user}")
ncheck = cursor.fetchone()[0]
url = message.attachments[0]['url']
await download_file(url, "db/" + str(message.author) + "/Notlar/" + dersargumani + "/" + ncheck),
cursor.execute(f"UPDATE users SET ncheck = 'NULL' WHERE username LIKE {user}")
database.commit()
return await bot.send_message(message.channel, "Notunuz " + ncheck + " adı ile kayıt edildi." + message.author.mention)
else:
return await bot.send_message(message.channel, "Lütfen cevap fotoğrafını gönderin, iptal için iptal yazın." + message.author.mention)
return
@bot.command(pass_context=True) #soruya cevap vermek veya çözülmüş işaretlemek için.
async def a(ctx, *args):
global database
cursor = database.cursor()
user = f"'%{str(ctx.message.author)}%'"
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
path = "db/" + str(ctx.message.author) + "/Çözülmemiş/" + dersargumani
if dersargumani != "NULL" and len(args) == 1 and os.path.exists(path):
if os.path.isfile(path + "/" + dersargumani + args[0] + ".jpg"):
await bot.send_file(ctx.message.channel, path + "/" + dersargumani + args[0] + ".jpg")
await bot.send_message(ctx.message.channel, "bu soru için cevap gönderin, iptal için iptal yazın." + ctx.message.author.mention)
acheck = dersargumani + args[0] + ".jpg"
cursor.execute(f"UPDATE users SET acheck = '{acheck}' WHERE username LIKE {user}")
database.commit()
else:
await bot.send_message(ctx.message.channel, dersargumani + args[0] + " adında bir soru bulunamadı" + ctx.message.author.mention)
return
@bot.command(pass_context=True)
async def d(ctx, *args):
global database
cursor = database.cursor()
user = f"'%{str(ctx.message.author)}%'"
cursor.execute(f"SELECT dcheck FROM users WHERE username LIKE {user}")
dcheck = cursor.fetchone()[0]
if len(args) == 0 and dcheck == "0":
cursor.execute(f"UPDATE users SET dcheck = '1' WHERE username LIKE {user}")
database.commit()
return await bot.send_message(ctx.message.channel, "```\nGeometri = 1\nMatematikTYT = 2\nMatematikAYT = 3\nFizik = 4\nKimya = 5\nBiyoloji = 6\nTürkçe = 7\nCoğrafya = 8\nFelsefe = 9\nTarih = 10\nDin = 11\n```")
if len(ctx.message.attachments) > 0:
print("bu ifadeyle aynı anda soru eklenemez.")
if len(args) == 1:
if args[0] == "l":
return await bot.send_message(ctx.message.channel, "```\nGeometri = 1\nMatematikTYT = 2\nMatematikAYT = 3\nFizik = 4\nKimya = 5\nBiyoloji = 6\nTürkçe = 7\nCoğrafya = 8\nFelsefe = 9\nTarih = 10\nDin = 11\n```")
elif args[0] in {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'}:
cursor.execute(f"UPDATE users SET dcheck = '0' WHERE username LIKE {user}")
database.commit()
return await selectDers(ctx.message)
else:
print("geçersiz ders adı")
return await bot.send_message(ctx.message.channel, "geçersiz ders adı. Lütfen geçerli bir ders adı giriniz. yardım için /yardim " + ctx.message.author.mention)
else:
return await bot.send_message(ctx.message.channel, "Lütfen tek bir argüman giriniz. " + ctx.message.author.mention)
@bot.group(pass_context=True)
async def n(ctx):
if ctx.invoked_subcommand is None:
await bot.send_message(ctx.message.channel, 'yanlış .n komutu girildi.')
@n.command(pass_context=True)
async def ekle(ctx, *args):
global database
cursor = database.cursor()
user = f"'%{str(ctx.message.author)}%'"
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
if not os.path.exists("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/"):
os.makedirs("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/")
if len(args) > 1:
if args[0] == "foto":
imname = args[1] + ".jpg"
cursor.execute(f"UPDATE users SET ncheck = '{imname}' WHERE username LIKE {user}")
database.commit()
return await bot.send_message(ctx.message.channel, "Lütfen " + args[1] + " fotoğrafını gönderiniz." + ctx.message.author.mention)
notename = args[0]
count = 2
string1 = ctx.message.content.split(' ', 2)[2]
note = await aiofiles.open("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/" + notename, "w")
await note.write(string1)
await note.close()
return await bot.send_message(ctx.message.channel, notename + " adlı notunuz kayıt edildi. " + ctx.message.author.mention)
else:
return await bot.send_message(ctx.message.channel, "Lütfen not adı ve içeriğini giriniz." + ctx.message.author.mention)
return
@n.command(pass_context=True)
async def göster(ctx, *args):
global database
cursor = database.cursor()
user = f"'%{str(ctx.message.author)}%'"
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
count = 0
if not os.path.exists("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/"):
return await bot.send_message(ctx.message.channel, "bu derse kayıtlı hiçbir notunuz yok." + ctx.message.author.mention)
if len(args) == 1: #sonra çoklu not gösterme eklenecek.
if os.path.isfile("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/" + args[0] ):
print("metin notu var")
notename = args[0]
note = await aiofiles.open("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/" + notename, "r")
notecontent = await note.read()
await bot.send_message(ctx.message.channel, notecontent)
count = 1
if os.path.isfile("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/" + args[0] + ".jpg"):
print("foto notuda var")
count = 1
await bot.send_file(ctx.message.channel, "db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/" + args[0] + ".jpg")
else:
if count == 0:
await bot.send_message(ctx.message.channel, args[0] + " adında bir not bulunamadı. " + ctx.message.author.mention)
else:
return await bot.send_message(ctx.message.channel, "sadece bir argüman giriniz " + ctx.message.author.mention)
return
@n.command(pass_context=True)
async def sil(ctx, *args):
global database
cursor = database.cursor()
user = f"'%{str(ctx.message.author)}%'"
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
if not os.path.exists("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/"):
os.makedirs("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/")
if len(args) == 1: #sonra çoklu not ekleme eklenecek.
if os.path.isfile("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/" + args[0]):
os.remove("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/" + args[0])
return await bot.send_message(ctx.message.channel, args[0] + " adındaki not silindi " + ctx.message.author.mention)
else:
return await bot.send_message(ctx.message.channel, args[0] + " adında bir not bulunamadı. " + ctx.message.author.mention)
else:
return await bot.send_message(ctx.message.channel, "sadece bir argüman giriniz " + ctx.message.author.mention)
return
@n.command(pass_context=True)
async def liste(ctx, *args):
global database
cursor = database.cursor()
user = f"'%{str(ctx.message.author)}%'"
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
if not os.path.exists("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/"):
os.makedirs("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/")
filelist = os.listdir("db/" + str(ctx.message.author) + "/Notlar/" + dersargumani + "/")
filecount = len(filelist)
i = 0
string1 = '```\n'
while i != filecount:
string1 = string1 + filelist[i] + '\n'
i = i + 1
string1 = string1 + '```'
return await bot.send_message(ctx.message.channel, string1)
@bot.command(pass_context=True)
async def hepsi(ctx, *args):
if await sudo_check(ctx.message):
i = 0
global database
cursor = database.cursor()
user = f"'%{str(ctx.message.author)}%'"
cursor.execute(f"SELECT ders FROM users WHERE username LIKE {user}")
dersargumani = cursor.fetchone()[0]
kacTane=len(os.listdir("db/" + str(ctx.message.author) + "/Çözülmemiş/" + dersargumani))
while(i != kacTane-1):
path = "db/" + str(ctx.message.author) + "/Çözülmemiş/" + dersargumani
if os.path.exists(path):
if os.path.isfile(path + "/" + dersargumani +str(i+1) + ".jpg"):
await bot.send_file(ctx.message.channel, path + "/" + dersargumani + str(i+1) + ".jpg")
else:
await bot.send_message(ctx.message.channel, dersargumani + str(i+1) + " adında bir soru bulunamadı" + ctx.message.author.mention)
if os.path.isfile("db/" + str(ctx.message.author) + "/Çözülmüş/" + dersargumani + "/" + dersargumani + str(i+1) + ".jpg"):
await bot.send_file(ctx.message.channel, "db/" + str(ctx.message.author) + "/Çözülmüş/" + dersargumani + "/" + dersargumani + str(i+1) + ".jpg")
i = i + 1
else:
i = i + 1
await bot.send_message(ctx.message.channel, dersargumani + " dersine kayıtlı hiçbir soru yok." + ctx.message.author.mention)
else:
return await bot.send_message(ctx.message.channel, "Bu komutu kullanmanız için gereken yetkilere sahip değilsiniz." + ctx.message.author.mention)
async def sudo_check(message: Message):
global database
cursor = database.cursor()
user = f"'%{str(message.author)}%'"
cursor.execute(f"SELECT sudo FROM users WHERE username LIKE {user}")
sudo = cursor.fetchone()[0]
if sudo == "1":
print("Kullanıcı " + str(message.author) + " sudo yetkilerine sahip, izin verildi.")
return True
else:
await bot.send_message(message.channel, message.author.mention + " sudo yetkilerine sahip değil, bu olay raporlanacak")
return False
@bot.group(pass_context=True)
async def sudo(ctx):
if not await sudo_check(ctx.message):
ctx.invoked_subcommand = None
return
if ctx.invoked_subcommand is None:
await bot.send_message(ctx.message.channel, 'yanlış .sudo komutu girildi.')
@sudo.command(pass_context=True)
async def yazi(ctx, *args):
try:
await bot.delete_message(ctx.message)
except:
print("bot mesaj düzenleme yetkisine sahip değil veya bu mesaj DM ile gönderildi.")
count = 1
string1 = args[0]
while (count != len(args)):
string1 = string1 + " " + args[count]
count = count + 1
return await bot.send_message(ctx.message.channel, string1)
@sudo.command(pass_context=True)
async def restart(ctx):
#process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE)
#await bot.send_message(ctx.message.channel, str(process.communicate()[0], "utf-8"))
await bot.send_message(ctx.message.channel, 'Restarting...')
os.execl("botstart.py", sys.argv[0])
tokenfile = open("db/token", "r")
token = tokenfile.read()
tokenfile.close()
bot.run(token)