-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtesting.py
More file actions
112 lines (69 loc) · 2.72 KB
/
testing.py
File metadata and controls
112 lines (69 loc) · 2.72 KB
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
#bot to keep track of how many and how often games are played on discord
#made by gurg
import discord
import sys
import logging
import time
import re
from config.config import TOKEN
from user import *
from generate_output import generate_output
logging.basicConfig(level=logging.INFO)#logs errors and debug info
#TODO
#implement sql stuff[x]
#implement commands to actually use the bot[x]
#Add functionality to allow people to pm the bot and get thier own personal gametimes[]
#Add commands so people can query gametimes about specific games[]
#get a better name[x]
#get a profile pic[]
#changed it so it displays the start and stop messages in different colours[x]
#implent a way to gradually add times to db(say every 10 mins)[]
#global variables-------------------------------------------
current_playing = [] #
current_users = [] # list of just the users, makes it easy to check if they are playing something already
if TOKEN == "":
print ("TOKEN not found, please add it in the config.py file.")
sys.exit(0)
def find_game(activities):
# if the activities is a tuple check all the elements to work out if one of them is a game
if (isinstance(activities, tuple)):
for i in range(len(activities)):
if isinstance(activities[i], discord.Game):
return activities[i]
#if a game cant be found return false
return None
# if its not a tuple still check it
elif isinstance(activities, discord.Game):
return activities
return None
client = discord.Client()
@client.event
async def on_ready():
print("The bot is ready!")
await client.change_presence(activity=discord.Game(name="Selling your data..."))
@client.event
async def on_message(message):
if message.author.id == client.user.id: # dont trigger on own messages, redundant? yeah but i cba testing
return
if message.content == "test":
try:
print(message.author.activities[0])
except IndexError:
print("not playing anything")
else:
output = isinstance(message.author.activities[0], discord.Game)
await message.channel.send(output)
if message.content == "test-fg":
if find_game(message.author.activities):
print(type(find_game(message.author.activities)))
else:
print("not playing a game")
#write a function that updates the database with info
@client.event
async def on_member_update(before, after):
c_time = time.strftime("%H:%M:%S") #current time
b_game = find_game(before.activities)
a_game = find_game(after.activities)
print ("BEFORE: "+ str(b_game))
print ("AFTER: "+ str(a_game))
client.run(TOKEN)