-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
146 lines (111 loc) · 5.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import discord
from discord.ext import commands
import json
import pandas as pd
import tabulate
from dotenv import load_dotenv
import os
from correctbranch import CorrectedBranch
from models import *
databaseFile = open('database.json',)
data = json.load(databaseFile)
load_dotenv('.env')
# TODOs:
# Return the table when mentioned
# Category command
# Add Random facts about Manipal
bot = commands.Bot(command_prefix='.', help_command=None,
description="This bot returns the cutoffs")
# df = pd.DataFrame.from_dict(data['branches'])
# print(df)
facts = []
def GetCutoff(branch):
print(type(branch))
# print(data['branches'])
print(len(data['branches']))
cutoffSearch = 0
roundName = ''
for i in data['branches']:
# print("Current i is", i)
if(i['name'].lower() == str(branch).lower()):
# print("if wala i is", i)
cutoffSearch = i
roundName = i['3rd_round']
# else:
# print("asdasdasd i is", i)
if(cutoffSearch != 0):
branchString = f"Cutoffs for the branch **{branch.upper()}**: \n\n2021 Counselling: \n4th Round: **{str(cutoffSearch['4th_round'])}.** \n3rd Round: **{str(cutoffSearch['3rd_round'])}.** \n\n2020: **{str(cutoffSearch['cutoff_2020'])}.** \n2019: **{str(cutoffSearch['cutoff_2019'])}.**"
print(f"<{cutoffSearch['link']}>")
linkString = f"The course outline for **{branch.upper()}** can be found at: <{cutoffSearch['link']}>"
zeroString = f"0 --> indicates that the no. of seats quota wasn't filled for the particular branch and anyone was eligible for them"
branchMessage = branchString + "\n" + zeroString + "\n\n" + linkString
return branchMessage, linkString
else:
return "Sorry! You have entered an invalid command. Try .help to get the list of commands"
@bot.event
async def on_ready():
print("I am alive on the MTTN Server")
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='https://bit.ly/MTTNMOVIE (link is all caps)'))
@bot.command()
async def ping(ctx):
await ctx.send("yo")
print("found")
@bot.command()
async def something(ctx):
await ctx.send('pong')
@bot.command(name="cutoff")
async def cutoff(ctx, *, arg):
correctedBranch = CorrectedBranch(arg)
cutoff, courseString = GetCutoff(correctedBranch)
await ctx.channel.send("Hey! " + ctx.author.mention + "\n")
await ctx.channel.send(cutoff)
@bot.command(name="course")
async def cutoff(ctx, *, arg):
correctedBranch = CorrectedBranch(arg)
cutoff, courseString = GetCutoff(correctedBranch)
await ctx.channel.send("Hey! " + ctx.author.mention + "\n")
await ctx.channel.send(courseString)
@bot.command()
async def fact(ctx):
await ctx.send("Facts: Coming soon!")
@bot.command()
async def help(ctx):
helpString = f'```(1) Mention me @MTTN Bot to get the branch wise cutoff table \n\n(2) Use ".cutoff branch" -> Get the cutoff and course structure \nEg: .cutoff EE --> Returns the information about Electrical and Electronics \n\n(3) Use ".guide" -> Freshers guide to Manipal \n\n(4) Use ".laptop" -> Laptop Guide for freshers\n\n(5) Use ".course branch" -> Returns the syllabus of that branch ```'
await ctx.channel.send("Here is a list of commands that you can use:" + helpString)
@bot.command()
async def laptop(ctx):
await ctx.channel.send("Hey! Here is the MTTN's recommended laptop guide: <https://www.manipalthetalk.org/manipal/freshers-guide/mttns-laptop-buying-guide-for-college/>")
await ctx.channel.send("Also check out our freshers portal which contains all the information that you might need: <https://freshers.manipalthetalk.org/> ")
@bot.command()
async def guide(ctx):
await ctx.channel.send("Hey! " + ctx.author.mention + "\n")
await ctx.channel.send("We have compiled a list of all the resources that you might need as a fresher at Manipal: <https://freshers.manipalthetalk.org/> ")
@bot.listen()
async def on_message(message):
for x in message.mentions:
if (x == bot.user):
await message.channel.send("Hey! " + message.author.mention + "\nI am your friendly neightbourhood bot. Here is the cutoffs table for the last year for each branch")
df = pd.DataFrame.from_dict(data['branches'])
df = df.drop(['link', 'cutoff_2019', '3rd_round'], axis=1)
df.columns = ["Branch Name",
"Latest (2021 2nd Round)", "2020 Cutoff"]
df.reset_index(drop=True, inplace=True)
print(df)
await message.channel.send(f"```{df}``` \n\n 0 --> indicates that the no. of seats quota wasn't filled for the particular branch and anyone was eligible for them")
await message.channel.send("**NOTE:** The data is not 100\% accurate")
await message.channel.send('\nYou can also use the command **".cutoff branchname"** to get the information of a particular branch \nOr use the ".help" command to get help ')
# df = pd.json_normalize(data['branches'])
# print(df)
# print table
# await message.channel.send(message.author.mention)
bot.run(os.getenv('TOKEN'))
# @bot.event
# async def on_message(message):
# if bot.user.mentioned_in(message):
# await message.channel.send("hogaysa mention")
# await message.channel.send(message.author.mention)
# @bot.command(name="ping")
# async def ping(ctx):
# await ctx.channel.send("Yo")
# def createMessage(branch):
# for key