-
Notifications
You must be signed in to change notification settings - Fork 2
/
SmokingCord_Revised.py
457 lines (355 loc) · 19.1 KB
/
SmokingCord_Revised.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
#------------------------------------------------------#
import time
import interactions
from interactions import Button, ButtonStyle, ActionRow
from pymongo import MongoClient
from bson.objectid import ObjectId
from urllib.parse import quote_plus
#------------------------------------------------------#
# Encode your MongoDB username and password
username = quote_plus('username')
password = quote_plus('password')
#------------------------------------------------------#
#Discord Variable for running the bot
#------------------------------------------------------#
bot = interactions.Client(
token="your token",
intents=interactions.Intents.DEFAULT | interactions.Intents.GUILD_MESSAGE_CONTENT,)
#------------------------------------------------------#
#MongoDB Variable for connecting to the database
#------------------------------------------------------#
client = MongoClient(f'mongodb+srv://urlConnectionString')
db = client.ZaZaDB
UserCollection = db.users
#------------------------------------------------------#
#Creation of the bot status
#------------------------------------------------------#
@bot.event
async def on_start():
await bot.change_presence(
presence=interactions.ClientPresence(
status=interactions.StatusType.ONLINE,
activities=[
interactions.PresenceActivity(
name="Helping SMOKINGCORD members",
type=interactions.PresenceActivityType.GAME,
created_at=int(time.time()),
details="sdsds",
state="sdsdsd",
assets=interactions.PresenceAssets(large_image='logo-real-3d-effect')
)
]
)
)
print("--------------")
print("Done loading")
print("--------------")
#------------------------------------------------------#
#Creation of the bot panel command where we will manage all our commands
#------------------------------------------------------#
@bot.command(name='panel',description="Responds with holder verification panel")
async def components_command(ctx: interactions.CommandContext):
#------------------------------------------------------#
#Creation of the differents buttons
#------------------------------------------------------#
VerificationButton = Button(
style=ButtonStyle.SUCCESS,
custom_id="count",
label="Count your cigarettes"
)
OneButton = Button(
style=ButtonStyle.SUCCESS,
custom_id="count1",
emoji=interactions.Emoji(name="1️⃣")
)
TwoButton = Button(
style=ButtonStyle.SUCCESS,
custom_id="count2",
emoji=interactions.Emoji(name="2️⃣")
)
ThreeButton = Button(
style=ButtonStyle.SUCCESS,
custom_id="count3",
emoji=interactions.Emoji(name="3️⃣")
)
DailyButton= Button(
style=ButtonStyle.PRIMARY,
custom_id="infodaily",
label="Check daily stats"
)
TotalButton= Button(
style=ButtonStyle.PRIMARY,
custom_id="infototal",
label="Check total stats"
)
#------------------------------------------------------#
#Creation of the main embeed
#------------------------------------------------------#
embed = interactions.Embed(title='SMOKINGCORD:', color=0xff0000)
embed.add_field(name=f"Welcome to the SMOKINGCORD - Bot:", value=f"SMOKINGCORD - Bot helps keeping track of a person's cigarette consumption. By pressing the **1**, **2**, or **3** buttons, the user can add one, two, or three cigarettes to the counter, making the registration process quick and intuitive.\n \nThe bot also allows the user to monitor their cigarette consumption over time and provides statistics such as the daily or weekly average of cigarettes smoked, helping the user make more informed decisions about their health and lifestyle.\n", inline=False)
embed.set_image(url=f'https://cdn.discordapp.com/attachments/768546282674716677/1078045572990255234/anime-cigarette.gif')
embed.set_footer(text='SMOKINGCORD - Counter', icon_url='https://cdn.discordapp.com/attachments/768546282674716677/1078045564010237992/anime-boy-smoking.gif')
action_row1= ActionRow(components=[VerificationButton, OneButton,TwoButton,ThreeButton])
action_row2= ActionRow(components=[DailyButton,TotalButton])
await ctx.send(embeds=embed, components=[action_row1,action_row2])
#------------------------------------------------------#
#Creation of the id=count button function
#------------------------------------------------------#
@bot.component("count")
async def count_function(ctx: interactions.ComponentContext):
text = interactions.TextInput(
style=interactions.TextStyleType.SHORT,
label="How much did you smoke?",
custom_id="text_input_response",
min_length=1,
max_length=2,
)
modal = interactions.Modal(
title="Application Form",
custom_id="mod_app_form",
components=[text],
)
userid= ctx.author.id._snowflake
datagiorno=ctx.created_at.day
datamese=ctx.created_at.month
dataanno=ctx.created_at.year
query = { "UserId": f"{userid}" }
# use the count_documents() method to retrieve the number of matching documents
#num_matching_docs = UserCollection.count_documents(query)
if (UserCollection.count_documents(query) == 0):
user = {"UserId": f"{userid}", "Name": f"{ctx.author.name}", "ServerId": f"{ctx.guild.id}","LastUse": f"{datagiorno}/{datamese}/{dataanno}" ,"DailyCount": 0, "TotalCount": 0}
UserCollection.insert_one(user)
#------------------------------------------------------#
#Sending text field pop-up
#------------------------------------------------------#
await ctx.popup(modal)
@bot.modal("mod_app_form")
async def modal_response(ctx, response: int):
userid= ctx.author.id._snowflake
datagiorno=ctx.created_at.day
datamese=ctx.created_at.month
dataanno=ctx.created_at.year
if int(response) >0:
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
date = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "LastUse": 1})
if (date['LastUse'] == (f"{datagiorno}/{datamese}/{dataanno}")):
try:
print("Adding to the database...")
# define the filter to find the document to update
DailyCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "DailyCount": 1})['DailyCount']
TotalCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "TotalCount": 1})['TotalCount']
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
updatedaily = { "$set": { "DailyCount": DailyCount + int(response) }}
updatetotal = { "$set": { "TotalCount": TotalCount + int(response) } }
# update the document
UserCollection.update_one(filter, updatedaily)
UserCollection.update_one(filter, updatetotal)
await ctx.send(f"Data updated thanks", ephemeral=True)
except:
await ctx.send(f"Please type a correct value", ephemeral=True)
else:
try:
TotalCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "TotalCount": 1})['TotalCount']
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
updatelastuse = { "$set": { "LastUse": f"{datagiorno}/{datamese}/{dataanno}"}}
updatetotal = { "$set": { "TotalCount": TotalCount + int(response) } }
updatedaily = { "$set": { "DailyCount": int(response) }}
# update the document
UserCollection.update_one(filter, updatelastuse)
UserCollection.update_one(filter, updatetotal)
UserCollection.update_one(filter, updatedaily)
await ctx.send(f"Data updated thanks", ephemeral=True)
except:
await ctx.send(f"Please type a correct value", ephemeral=True)
else:
await ctx.send(f"Please type a correct value", ephemeral=True)
#------------------------------------------------------#
#Creation of the id=infodaily button function
#------------------------------------------------------#
@bot.component("infodaily")
async def info_function(ctx: interactions.ComponentContext):
userid= ctx.author.id._snowflake
datagiorno=ctx.created_at.day
datamese=ctx.created_at.month
dataanno=ctx.created_at.year
query = { "UserId": f"{userid}" }
# use the count_documents() method to retrieve the number of matching documents
#num_matching_docs = UserCollection.count_documents(query)
if (UserCollection.count_documents(query) == 0):
user = {"UserId": f"{userid}", "Name": f"{ctx.author.name}", "ServerId": f"{ctx.guild.id}","LastUse": f"{datagiorno}/{datamese}/{dataanno}" ,"DailyCount": 0, "TotalCount": 0}
UserCollection.insert_one(user)
else:
date = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "LastUse": 1, "DailyCount": 1})
if (date['LastUse'] == (f"{datagiorno}/{datamese}/{dataanno}")):
await ctx.send(f"You smoked {date['DailyCount']} cigarettes", ephemeral=True)
else:
await ctx.send(f"You still need to smoke cigarettes today, congrats", ephemeral=True)
#------------------------------------------------------#
#Creation of the id=infototal button function
#------------------------------------------------------#
@bot.component("infototal")
async def info_function(ctx: interactions.ComponentContext):
userid= ctx.author.id._snowflake
datagiorno=ctx.created_at.day
datamese=ctx.created_at.month
dataanno=ctx.created_at.year
query = { "UserId": f"{userid}" }
# use the count_documents() method to retrieve the number of matching documents
#num_matching_docs = UserCollection.count_documents(query)
if (UserCollection.count_documents(query) == 0):
user = {"UserId": f"{userid}", "Name": f"{ctx.author.name}", "ServerId": f"{ctx.guild.id}","LastUse": f"{datagiorno}/{datamese}/{dataanno}" ,"DailyCount": 0, "TotalCount": 0}
UserCollection.insert_one(user)
else:
date = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "LastUse": 1, "TotalCount": 1})
await ctx.send(f"You smoked {date['TotalCount']} cigarettes", ephemeral=True)
#------------------------------------------------------#
#Creation of the id=count1 button function
#------------------------------------------------------#
@bot.component("count1")
async def add_one_function(ctx: interactions.ComponentContext):
userid= ctx.author.id._snowflake
datagiorno=ctx.created_at.day
datamese=ctx.created_at.month
dataanno=ctx.created_at.year
query = { "UserId": f"{userid}" }
# use the count_documents() method to retrieve the number of matching documents
#num_matching_docs = UserCollection.count_documents(query)
if (UserCollection.count_documents(query) == 0):
user = {"UserId": f"{userid}", "Name": f"{ctx.author.name}", "ServerId": f"{ctx.guild.id}","LastUse": f"{datagiorno}/{datamese}/{dataanno}" ,"DailyCount": 0, "TotalCount": 0}
UserCollection.insert_one(user)
else:
date = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "LastUse": 1})
if (date['LastUse'] == (f"{datagiorno}/{datamese}/{dataanno}")):
try:
print("Adding to the database...")
# define the filter to find the document to update
DailyCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "DailyCount": 1})['DailyCount']
TotalCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "TotalCount": 1})['TotalCount']
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
updatedaily = { "$set": { "DailyCount": DailyCount + 1 }}
updatetotal = { "$set": { "TotalCount": TotalCount + 1 } }
# update the document
UserCollection.update_one(filter, updatedaily)
UserCollection.update_one(filter, updatetotal)
await ctx.send(f"Data updated thanks", ephemeral=True)
except:
await ctx.send(f"Please type a correct value", ephemeral=True)
else:
try:
TotalCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "TotalCount": 1})['TotalCount']
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
updatelastuse = { "$set": { "LastUse": f"{datagiorno}/{datamese}/{dataanno}"}}
updatetotal = { "$set": { "TotalCount": TotalCount + 1 } }
updatedaily = { "$set": { "DailyCount": 1 }}
# update the document
UserCollection.update_one(filter, updatelastuse)
UserCollection.update_one(filter, updatetotal)
UserCollection.update_one(filter, updatedaily)
await ctx.send(f"Data updated thanks", ephemeral=True)
except:
await ctx.send(f"Please type a correct value", ephemeral=True)
#------------------------------------------------------#
#Creation of the id=count2 button function
#------------------------------------------------------#
@bot.component("count2")
async def add_one_function(ctx: interactions.ComponentContext):
userid= ctx.author.id._snowflake
datagiorno=ctx.created_at.day
datamese=ctx.created_at.month
dataanno=ctx.created_at.year
query = { "UserId": f"{userid}" }
# use the count_documents() method to retrieve the number of matching documents
#num_matching_docs = UserCollection.count_documents(query)
if (UserCollection.count_documents(query) == 0):
user = {"UserId": f"{userid}", "Name": f"{ctx.author.name}", "ServerId": f"{ctx.guild.id}","LastUse": f"{datagiorno}/{datamese}/{dataanno}" ,"DailyCount": 0, "TotalCount": 0}
UserCollection.insert_one(user)
else:
date = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "LastUse": 1})
if (date['LastUse'] == (f"{datagiorno}/{datamese}/{dataanno}")):
try:
print("Adding to the database...")
# define the filter to find the document to update
DailyCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "DailyCount": 1})['DailyCount']
TotalCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "TotalCount": 1})['TotalCount']
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
updatedaily = { "$set": { "DailyCount": DailyCount + 2 }}
updatetotal = { "$set": { "TotalCount": TotalCount + 2 } }
# update the document
UserCollection.update_one(filter, updatedaily)
UserCollection.update_one(filter, updatetotal)
await ctx.send(f"Data updated thanks", ephemeral=True)
except:
await ctx.send(f"Please type a correct value", ephemeral=True)
else:
try:
TotalCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "TotalCount": 1})['TotalCount']
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
updatelastuse = { "$set": { "LastUse": f"{datagiorno}/{datamese}/{dataanno}"}}
updatetotal = { "$set": { "TotalCount": TotalCount + 2 } }
updatedaily = { "$set": { "DailyCount": 2 }}
# update the document
UserCollection.update_one(filter, updatelastuse)
UserCollection.update_one(filter, updatetotal)
UserCollection.update_one(filter, updatedaily)
await ctx.send(f"Data updated thanks", ephemeral=True)
except:
await ctx.send(f"Please type a correct value", ephemeral=True)
#------------------------------------------------------#
#Creation of the id=count3 button function
#------------------------------------------------------#
@bot.component("count3")
async def add_one_function(ctx: interactions.ComponentContext):
userid= ctx.author.id._snowflake
datagiorno=ctx.created_at.day
datamese=ctx.created_at.month
dataanno=ctx.created_at.year
query = { "UserId": f"{userid}" }
# use the count_documents() method to retrieve the number of matching documents
#num_matching_docs = UserCollection.count_documents(query)
if (UserCollection.count_documents(query) == 0):
user = {"UserId": f"{userid}", "Name": f"{ctx.author.name}", "ServerId": f"{ctx.guild.id}","LastUse": f"{datagiorno}/{datamese}/{dataanno}" ,"DailyCount": 0, "TotalCount": 0}
UserCollection.insert_one(user)
else:
date = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "LastUse": 1})
if (date['LastUse'] == (f"{datagiorno}/{datamese}/{dataanno}")):
try:
print("Adding to the database...")
# define the filter to find the document to update
DailyCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "DailyCount": 1})['DailyCount']
TotalCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "TotalCount": 1})['TotalCount']
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
updatedaily = { "$set": { "DailyCount": DailyCount + 3 }}
updatetotal = { "$set": { "TotalCount": TotalCount + 3 } }
# update the document
UserCollection.update_one(filter, updatedaily)
UserCollection.update_one(filter, updatetotal)
await ctx.send(f"Data updated thanks", ephemeral=True)
except:
await ctx.send(f"Please type a correct value", ephemeral=True)
else:
try:
TotalCount = UserCollection.find_one({"UserId": f"{userid}"}, {"_id": 0, "TotalCount": 1})['TotalCount']
filter = { "UserId": f"{userid}" }
# define the update to apply to the document
updatelastuse = { "$set": { "LastUse": f"{datagiorno}/{datamese}/{dataanno}"}}
updatetotal = { "$set": { "TotalCount": TotalCount + 3 } }
updatedaily = { "$set": { "DailyCount": 3 }}
# update the document
UserCollection.update_one(filter, updatelastuse)
UserCollection.update_one(filter, updatetotal)
UserCollection.update_one(filter, updatedaily)
await ctx.send(f"Data updated thanks", ephemeral=True)
except:
await ctx.send(f"Please type a correct value", ephemeral=True)
#------------------------------------------------------#
#------------------------------------------------------#
bot.start()
#------------------------------------------------------#