Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daily counter #5

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions PRAIbot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# BY ADU - 28/11/21
# voice_version by AKOE and ADU - 2/12/21
# BY ADU and AKOE - 06/12/21
# Licence : CC-BY-NC-SA

import discord
Expand All @@ -22,11 +21,20 @@
!prai broadcast # In case of ULTIMATE emergency \n\
!prai voice # Send a voice file\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.1\nAuthor: ADU\nPython version: 3.9.2\nOS: Debian 11 Bullseye (amd64)\nHypervisor: ESXi 6.7U3"
versionmsg = "Bot: PRAIbot - Version 1.2\nAuthor: ADU\nPython version: 3.9.2\nOS: Debian 11 Bullseye (amd64)\nHypervisor: ESXi 6.7U3"

# 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()

client = discord.Client()

Expand All @@ -37,8 +45,13 @@ async def on_ready():

@bot.command()
async def prai(ctx, param: str=None):
# Read the daily counter
with open('count.txt', 'r+') as f:
cntr = f.readline()
f.close()
# 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:
Expand All @@ -49,18 +62,25 @@ async def prai(ctx, param: str=None):
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 == '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)
Expand Down