Skip to content

Commit 7791427

Browse files
committed
Issues and Requests cogs created
1 parent 65187e9 commit 7791427

File tree

8 files changed

+88
-34
lines changed

8 files changed

+88
-34
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ __pycache__/
66
# C extensions
77
*.so
88

9+
#Heroku
10+
Procfile
911
# Distribution / packaging
1012
.Python
1113
build/

Hackbot/__main__.py renamed to Hackbot/bot.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from discord.utils import find
88
from utils.db import new_hackathon
99
def main():
10-
token = "Nzk2NzI0MTkxNzUxNTY5NDc5.X_cFOQ.NYuv81J8cYlPBLic9L4d5UkyjSo"
11-
if not token:
10+
DISCORD_TOKEN = os.environ.get('DISCORD_TOKEN')
11+
if not DISCORD_TOKEN:
1212
logging.error('Token missing')
1313
return
1414

15-
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!hack '), case_sensitive=False)
15+
bot = commands.Bot(command_prefix=commands.when_mentioned_or(';hack '), case_sensitive=False)
1616
for filename in os.listdir('./cogs'):
1717
if filename.endswith('.py'):
1818
bot.load_extension(f'cogs.{filename[:-3]}')
@@ -37,7 +37,12 @@ async def on_guild_join(guild):
3737
if channel.permissions_for(guild.me).send_messages:
3838
await channel.send("```Hello guyss! HackBot is here to notify you all about the upcoming hackathons\nCommand Prefix: !hack\nFor help in commands type: !hack help```")
3939
break
40-
bot.run(token)
40+
41+
@bot.event
42+
async def on_command_error(ctx,error):
43+
if isinstance(error, commands.CommandNotFound):
44+
await ctx.send("Please type `;hack help` for list of commands")
45+
bot.run(DISCORD_TOKEN)
4146

4247
if __name__ == '__main__':
4348
main()

Hackbot/cogs/hackathons.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ def __init__(self,bot):
1414

1515
def get_channel_id(self,ctx,channel):
1616
channels = ctx.guild.text_channels
17-
print(channel)
1817
for i in channels:
1918
if i.name == channel:
20-
print(i.id)
2119
return i.id
2220
return False
2321

@@ -29,13 +27,14 @@ def save_channel_details(self, ctx, channel_id):
2927
update_channel(ctx.guild.id, channel_id)
3028

3129
async def create_channel(self,ctx,channel):
32-
await ctx.send("`Creating channel "+channel+"`")
30+
message = await ctx.send("```Creating channel "+channel+"```")
3331
await ctx.guild.create_text_channel(channel)
3432
channel_id = self.get_channel_id(ctx,channel)
33+
newcontent = "```Channel "+channel+" created and hacked for notifications.```"
34+
await message.edit(content=newcontent)
3535

3636
async def validate_channel(self,ctx, channel):
3737
channel = channel[0]
38-
print(channel)
3938
channel_id = self.get_channel_id(ctx,channel)
4039
if channel_id != False:
4140
self.save_channel_details(ctx,channel_id)
@@ -49,13 +48,13 @@ async def no_channel(self,ctx,channel):
4948

5049
@commands.guild_only()
5150
@commands.has_permissions(manage_channels=True,read_messages=True,send_messages=True)
52-
@commands.command(brief="Hack a channel for further hackathon updates")
53-
async def channel(self,ctx, *channel):
51+
@commands.command(brief="Hack a channel for upcoming hackathon notifications.")
52+
async def notify(self,ctx, *channel):
5453
await self.validate_channel(ctx,channel)
5554

5655
@commands.guild_only()
5756
@commands.has_permissions(manage_channels=True,read_messages=True,send_messages=True)
58-
@commands.command(brief="Unsubscribe the channel for further hackathon updates")
57+
@commands.command(brief="Unsubscribe the channel.")
5958
async def unsub(self,ctx):
6059
delete_guild(ctx.guild_id)
6160
await ctx.send("Unsubscribed")
@@ -121,16 +120,17 @@ async def check_list(self,hackathon):
121120
await self.single_embed(hackathon)
122121

123122
#Check after 1 minute if a new hackathon is added
124-
@tasks.loop(seconds=60.0)
123+
@tasks.loop(seconds=1860.0)
125124
async def check_if_new(self):
126125
hackathon = new_hackathon()
127-
print(hackathon)
126+
print("Running....")
128127
if len(hackathon) != 0:
129128
hackathon = sorted(hackathon, key=lambda x: x['website'])
130129
web_list = []
131130
k = hackathon[0]['website']
132131
for i in hackathon:
133-
if i['name'] == k:
132+
update_hackathon(i['name'], i['website'])
133+
if i['website'] == k:
134134
web_list.append(i)
135135
else:
136136
await self.check_list(web_list)
@@ -141,7 +141,6 @@ async def check_if_new(self):
141141

142142
@check_if_new.before_loop
143143
async def before_print(self):
144-
print("waiting..")
145144
await self.bot.wait_until_ready()
146145

147146

Hackbot/cogs/issues.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import discord
2+
from github import Github
3+
from discord.ext import commands, tasks
4+
import asyncio
5+
import os
6+
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
7+
g = Github(GITHUB_TOKEN)
8+
9+
repo = g.get_repo("starwiz-7/HackBot")
10+
11+
12+
class IssueError(commands.CommandError):
13+
pass
14+
15+
class Issue(commands.Cog):
16+
def __init__(self,bot):
17+
self.bot = bot
18+
19+
def create_issue(self,*issue):
20+
issue = issue[1]
21+
title = ""
22+
description = ""
23+
if len(issue) >1:
24+
title = issue[0]
25+
description = issue[1]
26+
repo.create_issue(title=title, body=description)
27+
else:
28+
title = issue[0]
29+
repo.create_issue(title=title)
30+
31+
32+
@commands.guild_only()
33+
@commands.command(brief="Request a feature, or report an issue.")
34+
async def issue(self,ctx, *issue):
35+
self.create_issue(ctx, issue)
36+
await ctx.send("Reported to HackBot developer.\nhttps://github.com/starwiz-7/HackBot")
37+
38+
def setup(bot):
39+
bot.add_cog(Issue(bot))

Hackbot/cogs/websites.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class SourceCogError(commands.CommandError):
66
pass
77

88
class Source(commands.Cog):
9-
def __inti__(self,bot):
9+
def __init__(self,bot):
1010
self.bot = bot
1111

1212
def parse_hackathons(self,hackathons):
@@ -17,7 +17,6 @@ def parse_hackathons(self,hackathons):
1717
l.append(i)
1818
k+=1
1919
if(k %5 == 0):
20-
# print(l)
2120
yield l
2221
k = 1
2322
l = []
@@ -34,18 +33,15 @@ async def web(self,ctx, *string):
3433
hackathons = get_hackathon(website)
3534
print(hackathons)
3635
if len(hackathons[0])>0:
37-
hackathons = list(self.parse_hackathons(hackathons))
36+
hackathon = list(self.parse_hackathons(hackathons))
3837
asset = get_asset(website)
39-
for i in hackathons:
40-
38+
for i in hackathon:
39+
print(i)
4140
msg = discord.Embed(title=f'Hackathons listed on {website}')
42-
# print(asset)
4341
msg.set_thumbnail(url=asset[0]['thumbnail'])
44-
# print(i[0])
4542
for j in i:
46-
# print(j)
47-
msg.add_field(name=j['name'],value=j['url'],inline=False)
48-
await ctx.send(embed=msg)
43+
await msg.add_field(name=j['name'],value=j['url'],inline=False)
44+
4945

5046

5147
def setup(bot):

Hackbot/requirements.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
aiohttp==3.7.3
2+
async-timeout==3.0.1
3+
attrs==20.3.0
4+
certifi==2020.12.5
5+
chardet==3.0.4
6+
Deprecated==1.2.11
7+
discord.py==1.6.0
8+
dnspython==2.1.0
9+
idna==2.10
10+
multidict==5.1.0
11+
PyGithub==1.54.1
12+
PyJWT==1.7.1
13+
pymongo==3.11.2
14+
requests==2.25.1
15+
typing-extensions==3.7.4.3
16+
urllib3==1.26.2
17+
wrapt==1.12.1
18+
yarl==1.6.3

Hackbot/utils/db.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
from datetime import datetime
22
from pymongo import MongoClient
3-
from mongotriggers import MongoTrigger
43
import pymongo
5-
import asyncio
6-
import logging
7-
import sys
8-
sys.path.append('..')
9-
client = MongoClient(
10-
"mongodb+srv://Admin:AdminHackBot@hackbot.g1uz8.mongodb.net/HackBot?retryWrites=true&w=majority"
11-
)
4+
import os
5+
MONGO_URI = os.environ.get('MONGO_URI')
6+
client = MongoClient(MONGO_URI)
127
bot_db = client.get_database("HackBot")
138
guilds = bot_db.get_collection("Guild-channels")
149
hackathons = bot_db.get_collection("Hackathons")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ To use HackBot, follow these steps:
4848
- Run the following command
4949

5050
```
51-
python __main__.py
51+
python bot.py
5252
```
5353

5454
## Roadmap

0 commit comments

Comments
 (0)