From 6c4053f1d8b491c16015cb250e5ec0812aaf2383 Mon Sep 17 00:00:00 2001 From: chengkangzai Date: Thu, 13 May 2021 20:41:23 +0800 Subject: [PATCH 1/2] Add Angry Mode --- AngryData.py | 69 +++++++++++++++++++++++++++++++++++++++ Data.py => DueDateData.py | 6 ++-- main.py | 69 +++++++++++++++++++++++++++++++-------- 3 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 AngryData.py rename Data.py => DueDateData.py (98%) diff --git a/AngryData.py b/AngryData.py new file mode 100644 index 0000000..0732ab6 --- /dev/null +++ b/AngryData.py @@ -0,0 +1,69 @@ +from Model.Context import Context +from Config import Config +import mysql.connector + + +class AngryData: + def __init__(self): + self.con = mysql.connector.connect( + host=Config().DB_HOST, + user=Config().DB_USERNAME, + password=Config().DB_PASSWORD, + database=Config().DB_DATABASE + ) + self.cursor = self.con.cursor(buffered=True) + print("Opened database successfully") + + def setUpTable(self): + print("Creating Table") + self.cursor.execute(''' + CREATE TABLE IF NOT EXISTS guild_angry( + id INT PRIMARY KEY AUTO_INCREMENT , + guild_id VARCHAR(255) NULL + ); + ''') + self.con.commit() + print("Table created successfully") + return self + + def setAngry(self, context: Context): + sql = f"""INSERT INTO guild_angry(guild_id) VALUES ({context.guild.id})""" + self.cursor.execute(sql) + self.con.commit() + + if self.cursor.rowcount <= 0: + raise Exception("Opps! There is some problem adding your record. Contact Bot maintainer to get helps") + return self + + def setNotAngry(self, context: Context): + sql = f"""DELETE FROM guild_angry WHERE guild_id={context.guild.id}""" + self.cursor.execute(sql) + self.con.commit() + + if self.cursor.rowcount <= 0: + raise Exception("Opps! There is some problem adding your record. Contact Bot maintainer to get helps") + return self + + def isGuildAngry(self, context: Context): + sql = f"""SELECT * FROM guild_angry WHERE guild_id={context.guild.id}; """ + self.cursor.execute(sql) + print(context.guild.id) + record = self.cursor.rowcount + return record == 1 + + +if __name__ == "__main__": + print("1. Initial Setup") + print("2. Get DB Detail") + operation = input("What do you want !?") + if operation == "1": + AngryData().setUpTable() + elif operation == "2": + print(f"""Operating under +DB_HOST = {Config().DB_HOST} +DB_USERNAME = {Config().DB_USERNAME} +DB_PASSWORD = {Config().DB_PASSWORD} +DB_DATABASE = {Config().DB_DATABASE} + """) + else: + exit(print("Invalid Input")) diff --git a/Data.py b/DueDateData.py similarity index 98% rename from Data.py rename to DueDateData.py index c1f0a47..9e3613b 100644 --- a/Data.py +++ b/DueDateData.py @@ -6,7 +6,7 @@ import mysql.connector -class Data: +class DueDateData: def __init__(self): self.con = mysql.connector.connect( @@ -202,9 +202,9 @@ def markAsDelete(self, context: Context, dueDateId: str): print("3. Get DB Detail") operation = input("What do you want !?") if operation == "1": - Data().setUpTable() + DueDateData().setUpTable() elif operation == "2": - Data().test() + DueDateData().test() elif operation == "3": print(f"""Operating under DB_HOST = {Config().DB_HOST} diff --git a/main.py b/main.py index 0b55a83..be06c87 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ -from Data import Data +from DueDateData import DueDateData +from AngryData import AngryData from Config import Config from discord.ext import commands from Model.Context import Context @@ -39,11 +40,17 @@ async def add(context: Context, subjectName: str = "", due_date: str = "", event "Or you enter a date that is already pass " )) - Data().add(context, subjectName, due_date, eventName) + DueDateData().add(context, subjectName, due_date, eventName) event = "[" + eventName + "]" if eventName != "" else "" - return await context.send(Helper.talkLikeABot(f"Due date for Subject:{subjectName}{event} on " - f"{str(due).split(' ')[0]} has been added")) + + isAngry = AngryData().isGuildAngry(context) + if isAngry: + return await context.send(Helper.talkLikeABot(f"Due Date fot this FUKING SUBJECT {subjectName}{event} on" + f"{str(due).split(' ')[0]} has been added")) + else: + return await context.send(Helper.talkLikeABot(f"Due date for Subject:{subjectName}{event} on " + f"{str(due).split(' ')[0]} has been added")) except Exception as e: return await context.send(e) @@ -52,7 +59,7 @@ async def add(context: Context, subjectName: str = "", due_date: str = "", event async def showAll(context: Context): """Find All Due date !ass show all """ try: - dueDates = Data().getAll(context) + dueDates = DueDateData().getAll(context) if len(dueDates) == 0: return await context.send(Helper.talkLikeABot(f"There is no due date setup yet")) @@ -68,7 +75,7 @@ async def find(context: Context, subjectName: str = ""): return await notEnoughArgs(context) try: - dueDates = Data().findBySubjectName(context, subjectName) + dueDates = DueDateData().findBySubjectName(context, subjectName) if len(dueDates) == 0: return await context.send(Helper.talkLikeABot(f"There is no due date name as : {subjectName}")) @@ -85,7 +92,7 @@ async def findID(context: Context, dueDateID: str = ""): return await notEnoughArgs(context) try: - dueDates = Data().findById(context, dueDateID) + dueDates = DueDateData().findById(context, dueDateID) if len(dueDates) == 0: return await context.send(Helper.talkLikeABot(f"There is no due date id as : {dueDateID}")) @@ -102,7 +109,8 @@ async def change(context: Context, subjectID: str = "", subjectName: str = "", d return await notEnoughArgs(context) try: - dueDates = Data().findById(context, subjectID) + dueDateData = DueDateData() + dueDates = dueDateData.findById(context, subjectID) if len(dueDates) == 0: return await context.send(Helper.talkLikeABot(f"There is no due date with id : {subjectID}")) @@ -110,12 +118,18 @@ async def change(context: Context, subjectID: str = "", subjectName: str = "", d if check.module_name == subjectName and check.due_date == parse(dueDate).date() and check.title == eventName: return await context.send(Helper.talkLikeABot("Are you try to change it to same content !? NO")) - db = Data().change(context, subjectID, subjectName, dueDate, eventName) + db = dueDateData.change(context, subjectID, subjectName, dueDate, eventName) if db.cursor.rowcount <= 0: return await context.send("Problem Occur") - return await context.send(Helper.talkLikeABot(f"Beep Bop ! Due Date with id : '{subjectID}' has been change ")) + isAngry = AngryData().isGuildAngry(context) + if isAngry: + return await context.send( + Helper.talkLikeABot(f"Due Date for this FUCKING Subject:{subjectName}{eventName} has been change ")) + else: + return await context.send( + Helper.talkLikeABot(f"Beep Bop ! Due Date with id : Subject:{subjectName}{eventName} has been change ")) except Exception as e: return await context.send(e) @@ -128,11 +142,23 @@ async def hole(context: Context, subjectID=""): return await notEnoughArgs(context) try: - if len(Data().findById(context, subjectID)) <= 0: + dueDateData = DueDateData() + dueDate = dueDateData.findById(context, subjectID) + if len(dueDate) <= 0: return await context.send(Helper.talkLikeABot(f"There is no due date with id : {subjectID}")) - Data().markAsDelete(context, subjectID) - return await context.send(Helper.talkLikeABot(f"Beep Bop ! Due Date with id : '{subjectID}' has been deleted ")) + dueDateData.markAsDelete(context, subjectID) + + subjectName = dueDate[0].module_name + event = dueDate[0].title + + isAngry = AngryData().isGuildAngry(context) + if isAngry: + return await context.send( + Helper.talkLikeABot(f"FUCK YOU [{subjectID}] {subjectName}{event} ! SUCH A ASSHOLE")) + else: + return await context.send( + Helper.talkLikeABot(f"Beep Bop ! Due Date with id : Subject:{subjectName}{event} has been deleted ")) except Exception as e: return await context.send(e) @@ -148,6 +174,23 @@ async def about(context: Context): """) +@bot.command('angry') +async def about(context: Context): + """Turn on/off angry mode """ + try: + data = AngryData() + isAngry = data.isGuildAngry(context) + if isAngry: + data.setNotAngry(context) + return await context.send("This server is CHILL right now") + else: + data.setAngry(context) + return await context.send("This server is FUCKING ANGRY right now") + + except Exception as e: + return await context.send(e) + + async def notEnoughArgs(context: Context): return await context.send(Helper.talkLikeABot( f""" From 80b40ba1536f64fc581bc27772004ddf90d18e66 Mon Sep 17 00:00:00 2001 From: chengkangzai Date: Thu, 13 May 2021 20:41:48 +0800 Subject: [PATCH 2/2] Bump the Version to 1.0.3 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index be06c87..f5958bf 100644 --- a/main.py +++ b/main.py @@ -166,7 +166,7 @@ async def hole(context: Context, subjectID=""): @bot.command('about') async def about(context: Context): """Show Info of this bot :3 """ - version = '1.0.2' + version = '1.0.3' await context.send(f""" Assignment Due Date Bot v{version} Hi there ! This project is created by chengkangzai (https://github.com/chengkangzai)