Skip to content

Commit

Permalink
Testing if code is lined properly - v3
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmaypardeshi committed Oct 19, 2023
1 parent 73b12a5 commit cbd9721
Showing 1 changed file with 2 additions and 83 deletions.
85 changes: 2 additions & 83 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ async def on_ready():
end_time DATETIME
)
''')

db.mutation_query('''
CREATE TABLE IF NOT EXISTS exams (
guild_id INT,
Expand All @@ -86,7 +85,6 @@ async def on_ready():
end_date DATETIME
)
''')

db.mutation_query('''
CREATE TABLE IF NOT EXISTS assignments (
guild_id INT,
Expand All @@ -96,7 +94,6 @@ async def on_ready():
date DATETIME
)
''')

db.mutation_query('''
CREATE TABLE IF NOT EXISTS qna (
guild_id INT,
Expand All @@ -105,23 +102,20 @@ async def on_ready():
qnumber INT
)
''')

db.mutation_query('''
CREATE TABLE IF NOT EXISTS regrade (
guild_id INT,
name VARCHAR(50),
questions VARCHAR(50)
)
''')

db.mutation_query('''
CREATE TABLE IF NOT EXISTS email_address (
author_id INT,
email_id VARCHAR(50),
is_active BOOLEAN NOT NULL CHECK (is_active IN (0, 1))
)
''')

db.mutation_query('''
CREATE TABLE IF NOT EXISTS rank (
user_id INT NOT NULL,
Expand Down Expand Up @@ -229,7 +223,6 @@ async def on_member_join(member):
await channel.send(f"Hello {member}! Your rank details are as follows. Level: 0, Experience: 0")
await member.send(f'You have joined {member.guild.name}!')


###########################
# Function: on_member_remove
# Description: run when member leaves a guild in which bot is alreay present
Expand Down Expand Up @@ -272,15 +265,12 @@ async def on_message(message):
if message.author.bot and message.author.id == Test_bot_application_ID:
ctx = await bot.get_context(message)
await bot.invoke(ctx)

if message.author == bot.user:
return

if profanity.check_profanity(message.content):
await message.channel.send(message.author.name + ' says: ' +
profanity.censor_profanity(message.content))
await message.delete()

await bot.process_commands(message)

if message.content == 'hey bot':
Expand All @@ -300,7 +290,6 @@ async def on_message(message):
text_file.close()
else:
pass

# Ranking System
if message.author.bot is False:
id_query = f"SELECT * FROM rank where user_id=?"
Expand All @@ -314,7 +303,6 @@ async def on_message(message):
update_query = f"UPDATE rank SET experience=? WHERE user_id=?"
db.mutation_query(update_query, (result[1]+1, message.author.id))


###########################
# Function: on_message_edit
# Description: run when a user edits a message
Expand Down Expand Up @@ -564,7 +552,6 @@ async def answer_question(ctx, q_num, answer):
await ctx.author.send('Please send answers to the #q-and-a channel.')
await ctx.message.delete()


@bot.command(name='regrade-request', help='add regrade-request')
async def submit_regrade_request(ctx,name:str,questions:str):

Expand Down Expand Up @@ -764,7 +751,6 @@ async def checkchart(ctx, name: str):
await ctx.send(f"Your requested chart:")
await ctx.send(f"{storage[name]['URL']}")


async def update_chart(storage, name, link):
"""
Updates the URL of the chart
Expand All @@ -783,21 +769,18 @@ async def update_chart(storage, name, link):
###########################

@bot.command(name='stats', help='shows bot stats')

async def show_stats(ctx):
embed = Embed(title="Bot stats",
colour=ctx.author.colour,
#thumbnail=bot.user.avatar_url,
timestamp=datetime.utcnow())

proc = Process()
with proc.oneshot():
uptime = timedelta(seconds=time()-proc.create_time())
cpu_time = timedelta(seconds=(cpu := proc.cpu_times()).system + cpu.user)
mem_total = virtual_memory().total / (1024**2)
mem_of_total = proc.memory_percent()
mem_usage = mem_total * (mem_of_total / 100)

fields = [
("Bot version", BOT_VERSION, True),
("Python version", python_version(), True),
Expand All @@ -807,10 +790,8 @@ async def show_stats(ctx):
("Memory usage", f"{mem_usage:,.3f} / {mem_total:,.0f} MiB ({mem_of_total:.0f}%)", True),
("Users", f"{ctx.guild.member_count:,}", True)
]

for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)

await ctx.send(embed=embed)
###########################
# Function: poll
Expand All @@ -826,43 +807,32 @@ async def show_stats(ctx):
polls=[]
scheduler = AsyncIOScheduler()


@bot.command(name='poll', help='Set Poll for a specified time and topic.')
@commands.has_role('Instructor')
async def create_poll(ctx, hours: int, question: str, *options):

if len(options) > 10:
await ctx.send("You can only supply a maximum of 10 options.")

else:
embed = Embed(title="Poll ‼",
description=question,
colour=ctx.author.colour,
timestamp=datetime.utcnow())

embed = Embed(title="Poll ‼",description=question,colour=ctx.author.colour,
timestamp=datetime.utcnow())
fields = [("Options", "\n".join([f"{numbers[idx]} {option}" for idx,
option in enumerate(options)]), False),
("Instructions", "React to cast a vote!", False),
("Duration","The Voting will end in "+str(hours)+" Minutes",False)]

for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)

message = await ctx.send(embed=embed)

for emoji in numbers[:len(options)]:
await message.add_reaction(emoji)

polls.append((message.channel.id, message.id))
scheduler.add_job(complete_poll, "interval",
minutes=hours,args=(message.channel.id, message.id))
scheduler.start()

async def complete_poll(channel_id, message_id):
message = await bot.get_channel(channel_id).fetch_message(message_id)

most_voted = max(message.reactions, key=lambda r: r.count)

await message.channel.send("The results are in and option "+most_voted.emoji+
" was the most popular with "+str(most_voted.count-1)+" votes!")
polls.remove((message.channel.id, message.id))
Expand All @@ -872,7 +842,6 @@ async def complete_poll(channel_id, message_id):
async def on_raw_reaction_add(payload):
if payload.message_id in (poll[1] for poll in polls):
message = await bot.get_channel(payload.channel_id).fetch_message(payload.message_id)

for reaction in message.reactions:
if (not payload.member.bot
and payload.member in await reaction.users().flatten()
Expand Down Expand Up @@ -902,26 +871,21 @@ async def custom_profanity(ctx, pword):
async def attend(ctx):
await attendance.compute(bot, ctx)


@bot.command(name='create_email', help='Configures the specified email address against user.')
async def create_email(ctx, email_id):
await email_address.create_email(ctx, email_id)


@bot.command(name='update_email', help='Updates the configured email address against user.')
async def update_email(ctx, email_id):
await email_address.update_email(ctx, email_id)


@bot.command(name='view_email', help='displays the configured email address against user.')
async def view_email(ctx):
await email_address.view_email(ctx)


@bot.command(name='remove_email', help='deletes the configured email address against user.')
async def delete_email(ctx):
await email_address.delete_email(ctx)

###########################
# Function: help
# Description: Describes the help
Expand All @@ -931,108 +895,66 @@ async def delete_email(ctx):
@bot.group(name='help', invoke_without_command=True)
async def custom_help(ctx):
await help_command.helper(ctx)


@custom_help.command('answer')
async def custom_answer(ctx):
await help_command.answer(ctx)


@custom_help.command('ask')
async def custom_ask(ctx):
await help_command.ask(ctx)


@custom_help.command('attendance')
async def custom_attendance(ctx):
await help_command.attendance(ctx)


@custom_help.command('begin-tests')
async def custom_begin_tests(ctx):
await help_command.begin_tests(ctx)


@custom_help.command('create')
async def custom_create(ctx):
await help_command.create(ctx)


@custom_help.command('end-tests')
async def custom_end_tests(ctx):
await help_command.end_tests(ctx)


@custom_help.command('oh')
async def custom_oh(ctx):
await help_command.oh(ctx)


@custom_help.command('ping')
async def custom_ping(ctx):
await help_command.ping(ctx)


@custom_help.command('poll')
async def custom_poll(ctx):
await help_command.poll(ctx)


@custom_help.command('setInstructor')
async def custom_setInstructor(ctx):
await help_command.setInstructor(ctx)


@custom_help.command('stats')
async def custom_stats(ctx):
await help_command.stats(ctx)


@custom_help.command('test')
async def custom_test(ctx):
await help_command.test(ctx)


@custom_help.command('regrade-request')
async def custom_regrade_request(ctx):
await help_command.regrade_request(ctx)


@custom_help.command('update-request')
async def custom_update_request(ctx):
await help_command.update_request(ctx)


@custom_help.command('display-requests')
async def custom_display_requests(ctx):
await help_command.display_requests(ctx)


@custom_help.command('remove-request')
async def custom_remove_request(ctx):
await help_command.remove_request(ctx)


@custom_help.command('create_email')
async def custom_create_email(ctx):
await help_command.create_email(ctx)


@custom_help.command('update_email')
async def custom_update_email(ctx):
await help_command.update_email(ctx)


@custom_help.command('remove_email')
async def custom_remove_email(ctx):
await help_command.remove_email(ctx)


@custom_help.command('view_email')
async def custom_view_email(ctx):
await help_command.view_email(ctx)


###########################
# Function: begin_tests
# Description: Start the automated testing
Expand All @@ -1043,12 +965,9 @@ async def custom_view_email(ctx):
async def begin_tests(ctx):
''' start test command '''
global TESTING_MODE

if ctx.author.id != Test_bot_application_ID:
return

TESTING_MODE = True

test_oh_chan = next((ch for ch in ctx.guild.text_channels
if 'office-hour-test' in ch.name), None)
if test_oh_chan:
Expand Down

0 comments on commit cbd9721

Please sign in to comment.