· 6 years ago · Dec 29, 2019, 05:10 PM
1# PACKAGES
2from discord.ext import commands
3import discord
4import sqlite3
5import json
6import os
7
8
9# TOKEN and BOT SETUP
10# token = os.getenv("token")
11token = 'NjUyNTUxNTMzNzc0MjQxODE2.XgZR2w.0T2g6zMWUyi4ICX5TjrjQbfcDPE'
12statistica = commands.Bot(command_prefix='>')
13
14# DATABASE SETUP
15conn = sqlite3.connect('statistics.db')
16db = conn.cursor()
17
18
19
20# THE BEGINNING
21
22
23
24# WHEN STATISTICA IS READY -
25
26@statistica.event
27async def on_ready():
28 db.execute(f"""CREATE TABLE IF NOT EXISTS servers (
29 server_name TEXT,
30 server_owner TEXT,
31 server_id INTEGER type UNIQUE,
32 select_emojis JSON,
33 emoji_count JSON,
34 emoji_average JSON,
35 emoji_timer JSON,
36 emoji_average_time JSON,
37 emoji_linechart JSON,
38 select_words JSON,
39 word_count JSON,
40 word_average JSON,
41 word_timer JSON,
42 word_average_time JSON,
43 word_linechart JSON,
44 member_count INTEGER,
45 member_growth INTEGER,
46 member_growth_average JSON,
47 member_growth_linechart JSON,
48 punishment_count JSON,
49 punishment_average JSON,
50 punishment_timer JSON,
51 punishment_average_time JSON,
52 punishment_linechart JSON,
53 disboard_count INTEGER,
54 disboard_bump_average JSON
55 )""")
56 conn.commit()
57 print("The bot is ready.")
58
59
60# WHEN STATISTICA JOINS A SERVER
61
62@statistica.event
63async def on_guild_join(guild):
64 db.execute("INSERT INTO servers VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
65 (guild.name, str(guild.owner), guild.id, json.dumps([]), json.dumps({}), json.dumps({}), json.dumps({}), json.dumps({}),
66 json.dumps({}), json.dumps([]), json.dumps({}), json.dumps({}), json.dumps({}), json.dumps({}), json.dumps({}), 0, 0, json.dumps([]), json.dumps([]),
67 json.dumps({}), json.dumps({}), json.dumps({}), json.dumps({}), json.dumps({}), 0, json.dumps([]),))
68 conn.commit()
69
70 server_join_embed = discord.Embed(title="Thanks for inviting me!", description="In a moment, I'll create a separate\
71 file for your server in my database and then, I'll work perfectly in your server! If you need help, feel free to join our support discord server\
72 - https://discord.gg/MhhqWcU", color=0x27EA27)
73 await guild.owner.send(embed=server_join_embed)
74
75
76# WHEN STATISTICA IS REMOVED FROM A SERVER
77
78@statistica.event
79async def on_guild_remove(guild):
80 db.execute(f"DELETE FROM servers WHERE server_id = ?", (guild.id))
81 conn.commit()
82
83
84
85# COMMANDS
86
87
88
89@statistica.command()
90async def add_emoji(ctx, *, emoji):
91 db.execute(f"SELECT select_emojis FROM servers WHERE server_id = ?", (ctx.guild.id,))
92 select_emojis = db.fetchone()
93 print(select_emojis)
94 select_emojis = select_emojis[0]
95 print(select_emojis)
96 select_emojis = json.loads(select_emojis)
97 print(select_emojis)
98 if len(select_emojis) == 3:
99 await ctx.send(f"Sorry, you can have a maximum of 3 tracked emojis. The three you have are '{select_emojis[0].strip('```')}', '{select_emojis[1].strip('```')}' and '{select_emojis[2].strip('```')}'")
100 select_emojis = []
101 return
102 else:
103 select_emojis = json.dumps(select_emojis)
104 print(select_emojis)
105 print(type(select_emojis))
106 db.execute(f'''UPDATE servers SET select_emojis=? WHERE server_id=?''', (select_emojis, ctx.guild.id))
107 conn.commit()
108 select_emojis = []
109 await ctx.send(f"Added '{emoji.strip('```')}' to the naughty list.")
110
111
112# RUN BOT
113
114statistica.run(token)