-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRAIbot.py
More file actions
178 lines (164 loc) · 7.06 KB
/
Copy pathPRAIbot.py
File metadata and controls
178 lines (164 loc) · 7.06 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
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
# By ADU and AKOE - 03/02/22
# Licence : CC-BY-NC-SA
#### IMPORTS ####
import discord
from discord.ext.commands.bot import Bot
from discord.ext import commands
import datetime
from blagues_api import BlaguesAPI
#################
#### TOKENS ####
# Get the Discord bot TOKEN
with open('BotToken.txt', 'r') as f:
TOKEN = f.readline()
f.close()
# Get the blague API TOKEN
with open('BlagueToken.txt', 'r') as f:
TOKENBLAGUE = f.readline()
f.close()
#################
#### Init ####
PREFIX = '!'
INTENTS = discord.Intents.default()
bot = commands.Bot(command_prefix=PREFIX, intents=INTENTS, case_insensitive=True) # case_insensitive to fix caps issue
blagues = BlaguesAPI(TOKENBLAGUE) # Blague API init
client = discord.Client()
jacky = True # Boolean to control Jacky usage
#################
# Is printed when !prai help is called
helpmsg = "Aide pour les gens perdus :\n\
```\
!prai # Calls PRAI\n\
!prai force # Mentions PRAI in case of emergency\n\
!prai broadcast # In case of ULTIMATE emergency \n\
!prai voice # Send a voice file\n\
!prai xplosion # Reads PRAI with TTS\n\
!prai joke # Tells a random funny joke\n\
!prai status # Returns the current activity of PRAI\n\
!prai version # Prints the version of the bot\n\
!prai stats # Returns the bot usage counter\n\
!prai help # Prints this help message\n\
```"
# Is printed when !prai version is called
versionmsg = "Bot: PRAIbot - Version 1.6\nAuthor: ADU\nPython version: 3.9.2\nOS: Debian 11 Bullseye (amd64)\nHypervisor: ESXi 6.7U3"
#### Functions ####
# Function to increment the usage counter by one
def appendToFile(cntr):
open('count.txt', 'w').close()
with open('count.txt', 'a') as f:
cntr += 1
f.write(str(cntr))
f.close()
# Function to check btw 2 times (for prai status)
def time_in_range(start, end, current):
return start <= current <= end
#################
@bot.event
async def on_ready():
print(f'Logged in as: {bot.user.name}')
print(f'With ID: {bot.user.id}')
@bot.command(pass_context = True)
async def prai(ctx, param: str=None):
global jacky # Make the jacky variable global
# Read the daily counter
with open('count.txt', 'r+') as f:
cntr = f.readline()
f.close()
# For admin purposes only
if (ctx.message.author.id == 299572932307582976 and jacky == False):
return
# This is checking if the parameter is given or not
if (param is None):
appendToFile(int(cntr)) # Increment the usage counter
await ctx.send('**PRAI**')
return
else:
param = param.lower()
if (param == 'help'):
# If the parameter is 'help', then send the help guide
await ctx.send(helpmsg)
return
elif (param == 'broadcast'):
# If the parameter is 'help', then send the help guide
appendToFile(int(cntr)) # Increment the usage counter
await ctx.send('**PRAI** <@&915525095835967519>')
return
elif (param == 'force'):
# If the parameter is 'force', then mention PRAI
appendToFile(int(cntr)) # Increment the usage counter
await ctx.send('**PRAI** <@131170813444358144>')
return
elif (param == 'version'):
# If the parameter is 'version', send information about the bot
await ctx.send(versionmsg)
return
elif (param == 'stats'):
# If the parameter is 'stats', then return the counter
await ctx.send(f"Le bot a déjà crié **PRAI** {str(cntr)} fois dans sa vie")
return
elif (param == 'xplosion'):
# If the parameter is 'xplosion', the read the msg with TTSs
appendToFile(int(cntr)) # Increment the usage counter
await ctx.send("pérai", tts=True)
return
elif (param == 'joke'):
# If the parameter is 'joke', return a random joke
appendToFile(int(cntr)) # Increment the usage counter
blague = await blagues.random()
await ctx.send(blague.joke) # Send the joke
await ctx.send(f"||{blague.answer}||") # Send the answer
return
elif (param == 'voice'):
# If the parameter is 'voice', send a voice file
appendToFile(int(cntr)) # Increment the usage counter
with open('prai.flac', 'rb') as f:
audio = discord.File(f)
await ctx.send(file = audio)
return
elif (param == 'jacky'):
# For admin usage only
if (ctx.message.author.id == 151379424967786496 or ctx.message.author.id == 316317238103769089): # if Alex or Alois
jacky = not jacky # Invert the jacky bool
await ctx.send(":white_check_mark:")
return
await ctx.send("Vous n'êtes pas autorisé à utiliser cette commande.") # If not admin
return
elif (param == 'status'):
# If the parameter is 'status', then return the status
appendToFile(int(cntr)) # Increment the usage counter
now = datetime.datetime.now().time() # Get current time
if (time_in_range(datetime.time(21, 30, 0), datetime.time(23, 59, 59), now)):
await ctx.send('**PRAI** fait dodo :zzz:')
return
elif (time_in_range(datetime.time(0, 0, 0), datetime.time(7, 0, 0), now)):
await ctx.send('**PRAI** fait dodo :zzz:')
return
elif (time_in_range(datetime.time(7, 0, 0), datetime.time(10, 0, 0), now)):
await ctx.send('**PRAI** fait ses petites emplettes :basket:')
return
elif (time_in_range(datetime.time(10, 0, 0), datetime.time(11, 45, 0), now)):
await ctx.send('**PRAI** regarde la TV :tv: #Motus')
return
elif (time_in_range(datetime.time(11, 45, 0), datetime.time(14, 15, 0), now)):
await ctx.send('**PRAI** mange :hamburger:')
return
elif (time_in_range(datetime.time(14, 15, 0), datetime.time(16, 30, 0), now)):
await ctx.send('**PRAI** fait la sieste :zzz:')
return
elif (time_in_range(datetime.time(16, 30, 0), datetime.time(17, 00, 0), now)):
await ctx.send('**PRAI** fait un test PCR :microbe:')
return
elif (time_in_range(datetime.time(17, 00, 0), datetime.time(18, 30, 0), now)):
await ctx.send('**PRAI** fait des mots croisés :pencil:')
return
elif (time_in_range(datetime.time(18, 30, 0), datetime.time(21, 30, 0), now)):
await ctx.send('**PRAI** prends le souper :ramen:')
return
return
else:
# If parameter is not recognized
with open('prai-perdu.jpg', 'rb') as f:
picture = discord.File(f)
await ctx.send(f'**PRAI** perdu, merci de réessayer. *#PRAYforPRAI*', file = picture)
return
bot.run(TOKEN)