From 9daf16c978c07962e4833e20dd1b8a9391fdd4d8 Mon Sep 17 00:00:00 2001 From: Alexandre Dpy Date: Mon, 6 Dec 2021 22:35:01 +0100 Subject: [PATCH 1/3] Added stats counter --- .gitignore | 1 + PRAIbot.py | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1351ca4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +count.txt \ No newline at end of file diff --git a/PRAIbot.py b/PRAIbot.py index 4f67778..b99703e 100644 --- a/PRAIbot.py +++ b/PRAIbot.py @@ -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 @@ -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() @@ -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: @@ -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 été utilisé : {str(cntr)} fois aujourd'hui.") + 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) From f1cef68f8b64e8aaccbcea9cbc793679f21ff0d4 Mon Sep 17 00:00:00 2001 From: Alexandre Dpy Date: Mon, 6 Dec 2021 22:43:31 +0100 Subject: [PATCH 2/3] Fix stats msg --- .gitignore | 1 - PRAIbot.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 1351ca4..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -count.txt \ No newline at end of file diff --git a/PRAIbot.py b/PRAIbot.py index b99703e..71d6417 100644 --- a/PRAIbot.py +++ b/PRAIbot.py @@ -76,7 +76,7 @@ async def prai(ctx, param: str=None): return elif (param == 'stats'): # If the parameter is 'stats', then return the counter - await ctx.send(f"Le bot a été utilisé : {str(cntr)} fois aujourd'hui.") + await ctx.send(f"Le bot a déjà crié **PRAI** {str(cntr)} fois") return elif (param == 'voice'): # If the parameter is 'voice', send a voice file From 25d2596093a882b7b6f6c42cb209a5791d367595 Mon Sep 17 00:00:00 2001 From: Alexandre Dpy Date: Mon, 6 Dec 2021 22:44:53 +0100 Subject: [PATCH 3/3] Fix stats msg --- PRAIbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PRAIbot.py b/PRAIbot.py index 71d6417..750d088 100644 --- a/PRAIbot.py +++ b/PRAIbot.py @@ -76,7 +76,7 @@ async def prai(ctx, param: str=None): 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") + 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