Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chengkangzai committed Dec 30, 2021
2 parents a538c5e + b307aa6 commit 164ff86
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 17 deletions.
69 changes: 69 additions & 0 deletions AngryData.py
Original file line number Diff line number Diff line change
@@ -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"))
6 changes: 3 additions & 3 deletions Data.py → DueDateData.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import mysql.connector


class Data:
class DueDateData:

def __init__(self):
self.con = mysql.connector.connect(
Expand Down Expand Up @@ -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}
Expand Down
71 changes: 57 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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"))

Expand All @@ -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}"))

Expand All @@ -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}"))

Expand All @@ -102,20 +109,27 @@ 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}"))

check = dueDates[0]
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)
Expand All @@ -128,26 +142,55 @@ 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)


@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)
Any bug report can create a issue at here https://tinyurl.com/assbotIssues
""")


@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"""
Expand Down

0 comments on commit 164ff86

Please sign in to comment.