-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
97 lines (71 loc) · 2.87 KB
/
main.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
import discord
from tinydb import TinyDB, where, Query
from tinydb.operations import increment
import datetime
client = discord.Client()
db = TinyDB("db.json")
config = TinyDB("config.json")
config_data = config.table("config")
users = db.table("users", cache_size=0)
pending = db.table("pending", cache_size=0)
STAFF_ID = config_data.all()[0]["STAFF_ID"]
TOKEN = config_data.all()[0]["TOKEN"]
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
print(f"PENDING ALL: {pending.all()}")
print(f"USERS ALL: {users.all()}")
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!rankup'):
author_id = str(message.author.id)
query = Query()
user = users.search(query.name == author_id)
if (len(user) == 0):
users.insert({"name": author_id, "rank": 1})
user = users.search(query.name == author_id)
rank = user[-1]['rank']
msg = f"{message.author.mention} requested a rank up. They are currently rank {rank}, and have been in the Discord for {datetime.datetime.utcnow() - message.author.joined_at}. <@&{STAFF_ID}> use emoticons to either grant or deny the rank up request."
print(msg)
outbound = await message.channel.send(msg)
print(f"OUTBOUND ID: {outbound.id}")
pending.insert({"message_id": outbound.id, "user": author_id})
await outbound.add_reaction("👍")
await outbound.add_reaction("👎")
elif message.content.startswith("!rank?"):
mentions = message.mentions
if len(mentions) == 0:
mentions = [message.author]
msg = ""
for i in mentions:
cur_id = str(i.id)
query = Query()
user = users.search(query.name == cur_id)
if (len(user) == 0):
users.insert({"name": cur_id, "rank": 1})
user = users.search(query.name == cur_id)
rank = user[-1]['rank']
msg += f"{i.mention} is rank {rank} \n\n"
print(msg)
await message.channel.send(msg)
@client.event
async def on_raw_reaction_add(payload):
if payload.user_id == client.user.id:
return
member_role_ids = list(map(lambda role: str(role.id), payload.member.roles))
if STAFF_ID not in member_role_ids:
print("someone reacted, but they're not staff")
return
query = Query()
pen = pending.search(query.message_id == payload.message_id)[0]
if str(payload.emoji) == "👍":
pending.remove(where('message_id') == payload.message_id)
users.update(where('name') == pen['user'], increment('rank'))
elif (str(payload.emoji) == "👎"):
print("thumbsdown from mod")
pending.remove(where('message_id') == payload.message_id)
else:
print(payload.emoji)
client.run(TOKEN)