diff --git a/.gitignore b/.gitignore
index a2da7e1..df1d76e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@ files/stats.json
files/lost.json
files/locked.json
files/database.json
+files/ufora_notifications.json
.idea/
__pycache__
.env
\ No newline at end of file
diff --git a/cogs/launch.py b/cogs/launch.py
index d0604ed..14568c7 100644
--- a/cogs/launch.py
+++ b/cogs/launch.py
@@ -8,6 +8,7 @@ import pytz
import requests
+# Temporarily disabled because of API (setup @ bottom)
class Launch(commands.Cog):
def __init__(self, client):
self.client = client
@@ -51,4 +52,5 @@ class Launch(commands.Cog):
def setup(client):
- client.add_cog(Launch(client))
+ pass
+ # client.add_cog(Launch(client))
diff --git a/cogs/oneliners.py b/cogs/oneliners.py
index 0c67f42..20bc822 100644
--- a/cogs/oneliners.py
+++ b/cogs/oneliners.py
@@ -6,6 +6,7 @@ from discord.ext import commands
from enums.help_categories import Category
from functions import checks, clap, mock, sunrise, timeFormatters
import pytz
+from requests import get
import time
import urllib.parse
@@ -101,7 +102,7 @@ class Oneliners(commands.Cog):
@commands.command(name="Todo", aliases=["List", "Td"])
@help.Category(category=Category.Didier)
- async def todo(self, ctx, *args):
+ async def todo(self, ctx):
await ctx.send("https://trello.com/b/PdtsAJea/didier-to-do-list")
@commands.command(name="LMGTFY", aliases=["Dsfr"], usage="[Query]")
@@ -130,7 +131,7 @@ class Oneliners(commands.Cog):
await ctx.send("Shut, it already is.")
@commands.command()
- async def sc(self, ctx, *args):
+ async def sc(self, ctx):
await ctx.send("http://take-a-screenshot.org/")
@commands.command(aliases=["os", "sauce", "src"])
@@ -144,9 +145,19 @@ class Oneliners(commands.Cog):
await ctx.send(":sunny:: **{}**\n:crescent_moon:: **{}**".format(s.sunrise(), s.sunset()))
@commands.command(name="Tias", aliases=["TryIt"])
- async def tias(self, ctx, *args):
+ async def tias(self, ctx):
await ctx.send("***Try it and see***")
+ @commands.command(name="Inspire")
+ @help.Category(Category.Other)
+ async def inspire(self, ctx):
+ image = get("http://inspirobot.me/api?generate=true")
+
+ if image.status_code == 200:
+ await ctx.send(image.text)
+ else:
+ await ctx.send("Uh oh API down.")
+
def setup(client):
client.add_cog(Oneliners(client))
diff --git a/cogs/tasks.py b/cogs/tasks.py
index d38e14c..b44bcac 100644
--- a/cogs/tasks.py
+++ b/cogs/tasks.py
@@ -6,6 +6,7 @@ from functions import timeFormatters
from functions.config import config
from functions.database import currency, poke, prison, birthdays, stats
from functions.scraping import getMatchweek
+from functions import ufora_notifications
import json
import random
import requests
@@ -24,6 +25,7 @@ class Tasks(commands.Cog):
self.updateMessageCounts.start()
self.sendReminders.start()
self.updateMatchweek.start()
+ self.uforaAnnouncements.start()
@tasks.loop(hours=1.0)
async def bankInterest(self):
@@ -238,6 +240,24 @@ class Tasks(commands.Cog):
async def beforeUpdateMatchweek(self):
await self.client.wait_until_ready()
+ @tasks.loop(minutes=30.0)
+ async def uforaAnnouncements(self):
+ """
+ Task that checks for new Ufora announcements every few minutes
+ """
+ # Get new notifications
+ announcements = ufora_notifications.run()
+
+ if announcements:
+ announcements_channel = self.client.get_channel(816724500136591380)
+
+ for an in announcements:
+ await announcements_channel.send(embed=an.to_embed())
+
+ @uforaAnnouncements.before_loop
+ async def beforeUforaAnnouncements(self):
+ await self.client.wait_until_ready()
+
def getCurrentHour(self):
return timeFormatters.dateTimeNow().hour
diff --git a/data/constants.py b/data/constants.py
index 0d3facf..8f8a9cb 100644
--- a/data/constants.py
+++ b/data/constants.py
@@ -14,11 +14,13 @@ botIDs = [
"728361496874057812"
]
BugReports = "762668401960812554"
+BotTesting = "679701786189103106"
CallOfCode = "626699611192688641"
CoCGeneral = "626699611813314561"
DeZandbak = "728361030404538488"
ErrorLogs = "762668505455132722"
FeatureRequests = "762668473313787964"
+ZandbakSpeeltuin = "769248992957038612"
mods = {
626699611192688641: [384457911377854467, 171671190631481345],
@@ -53,7 +55,12 @@ faq_channels = {
727876797458284584: "funcprog",
727876819264733244: "statprob",
727876836587208714: "sysprog",
- 676713433567199232: "didier"
+ 676713433567199232: "didier",
+ 807566495550013460: "comparch",
+ 807567007355895838: "multimedia",
+ 807567261216538644: "sel1",
+ 807567345484169237: "webdev",
+ 807567387775336499: "wetrek"
}
diff --git a/data/embeds/__init__.py b/data/embeds/__init__.py
new file mode 100644
index 0000000..55d7068
--- /dev/null
+++ b/data/embeds/__init__.py
@@ -0,0 +1 @@
+from .ufora import UforaNotification
diff --git a/data/embeds/ufora.py b/data/embeds/ufora.py
new file mode 100644
index 0000000..475110b
--- /dev/null
+++ b/data/embeds/ufora.py
@@ -0,0 +1,95 @@
+from datetime import datetime, timedelta
+from discord import Embed, Colour
+from functions.stringFormatters import leadingZero as lz
+from functions.timeFormatters import intToWeekday
+import pytz
+import re
+
+
+class UforaNotification:
+ def __init__(self, content: dict, course, notif_id, course_id):
+ self._content: dict = content
+ self._course = course
+ self._notif_id, self._course_id = notif_id, course_id
+ self._view_url = self._create_url()
+ self._title = self._clean_content(self._content["title"])
+ self._description = self._get_description()
+ self._published = self._get_published()
+
+ def to_embed(self):
+ embed = Embed(colour=Colour.from_rgb(30, 100, 200))
+
+ embed.set_author(name=self._course)
+ embed.title = self._title
+ embed.url = self._view_url
+ embed.description = self._description
+ embed.set_footer(text=self._published)
+
+ return embed
+
+ def get_id(self):
+ return int(self._notif_id) if self._notif_id is not None else self._content["id"]
+
+ def _create_url(self):
+ if self._notif_id is None or self._course_id is None:
+ return self._content["link"]
+
+ return "https://ufora.ugent.be/d2l/le/news/{0}/{1}/view?ou={0}".format(self._course_id, self._notif_id)
+
+ def _get_description(self):
+ desc = self._clean_content(self._content["summary"])
+
+ if len(desc) > 500:
+ return desc[:497] + "..."
+
+ return desc
+
+ def _clean_content(self, text: str):
+ # Dict with HTML & markdown tags to replace
+ html_table = {
+ # CHARACTERS:
+ "&": '&',
+ """: '"',
+ "apos;": "'",
+ ">": ">",
+ "<": "<",
+ # MARKDOWN SUPPORT:
+ "": "**",
+ "": "**",
+ "": "**",
+ "": "**",
+ "": "*",
+ "": "*",
+ "": "*",
+ "": "*",
+ "": "~~",
+ "": "~~",
+ "": "__",
+ "": "__",
+ # Represent paragraphs with newlines
+ "