-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasses.py
42 lines (41 loc) · 1.3 KB
/
Classes.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
#DB大概是这样子的
#注意,这个还是从Bot里面扒出来的,不是完整的,请勿单独使用
#参考!!!!!
import discord
import logging
import sqlite3
import json
from discord.ext import commands
logger = logging.getLogger('discord.CLASS')
class DB(object):
local = ''
def find(self,sql,mode ='fetchone'):
connect = sqlite3.connect(self.local)
pointer = connect.cursor()
try:
pointer.execute(sql)
except Exception as e:
logger.exception(f'Fail to find data!')
connect.close()
return -1
else:
if mode == 'fetchone':
#一元
try:
result = pointer.fetchone()
except Exception as e:
logger.exception(f'Fail to find data!')
connect.close()
return -1
elif mode == 'fetchall':
#二元
try:
result = pointer.fetchall()
except Exception as e:
logger.exception(f'Fail to find data!')
connect.close()
return -1
else:
logger.critical(f'Unknown Error')
connect.close()
return result