Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ebb6b05
Adding main Classes to the /classes/__init__.py , and modified other …
osam7a Jul 31, 2023
3ef88b1
Added pandas to requirements (QuestionQuery.py)
osam7a Jul 31, 2023
17feb16
Nicer ping command because why not
osam7a Jul 31, 2023
d11bddd
Use channel IDs for channel identifications (Rather than names)
osam7a Jul 31, 2023
90ad6cc
Renamed files: Always use snake case in Python, rather than camelCase…
osam7a Jul 31, 2023
6c9b60d
More renaming: camelCase to snake_case
osam7a Jul 31, 2023
6ef15e2
Moved views into a seperate folder (Just to organize things together)
osam7a Jul 31, 2023
932fae2
Rewrite help command
osam7a Jul 31, 2023
bcbf78d
Removed views.py (Mistake)
osam7a Jul 31, 2023
512938c
Added simple channel for 'Upcoming Events' (NOT WORKING YET, WILL ADD…
osam7a Aug 16, 2023
d3923fa
Added Upcoming Events channel and task loop (Fixed and working). MIGH…
osam7a Aug 16, 2023
d50a4f4
Set tasks loop interval for 10 minutes
osam7a Aug 16, 2023
1ce86ba
Saved all Channel objects as attributes for DiscordBot, and added Mem…
osam7a Aug 16, 2023
527a2a5
Changed "no events upcoming" to "no events yet"
osam7a Aug 16, 2023
49f6c27
Added mentions field in API for mentions on top of the webhook
osam7a Aug 16, 2023
ccfa8e1
Switched from tasks loop to using normal listeners
osam7a Aug 16, 2023
6885e4f
Removed unused import from misc.py
osam7a Aug 19, 2023
45bd9e1
Remove unused imports from issue_list view
osam7a Aug 19, 2023
0d12a9a
Basic paginator class
osam7a Aug 19, 2023
a8142ac
Removed pagination in issue listing (Pagination is handled within the…
osam7a Aug 19, 2023
c50a1c1
Better issue-list view system (NOT TESTED!!)
osam7a Aug 19, 2023
cb64254
unused import in listeners
osam7a Aug 19, 2023
feeeb15
unused import in github class
osam7a Aug 19, 2023
1b8026c
fixes for the new paginator system, and made it persistent
osam7a Aug 19, 2023
5dd6fa6
Added some doc strings, typehinting for the code I edited previously
osam7a Aug 20, 2023
9aea6b4
split the `Commands` cog into `Miscellaneuos` and `Programming`
osam7a Aug 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions micro/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from pydantic import BaseModel
from datetime import datetime

from classes.colored_embed import CEmbed
from classes import CEmbed
from static.constants import EVENTS_ROLE_ID

import os, aiohttp

Expand All @@ -16,13 +17,16 @@ class Event(BaseModel):
event_link: str
event_location: str
seats: int
mentions: list[int]


app = FastAPI()


def get_embed(event: Event):
date = datetime.strptime(event.date_time, "%Y-%m-%d")
date_time = event.date_time.split()
date = datetime.strptime(date_time[0], "%Y-%m-%d")
time = datetime.strptime(date_time[1], "%H:%M")
return CEmbed.from_dict(
{
"title": event.title,
Expand All @@ -40,7 +44,7 @@ def get_embed(event: Event):
},
{
"name": "Time",
"value": date.strftime("%H-%M"),
"value": time.strftime("%H:%M"),
"inline": True
},
{
Expand Down Expand Up @@ -73,5 +77,6 @@ async def publish_event(event: Event):
WB_URL = os.getenv("WEBHOOK_URL")

async with aiohttp.ClientSession() as session:
mentions = " ".join([f"<@&{id}>" for id in event.mentions])
webhook = Webhook.from_url(WB_URL, session=session)
await webhook.send(embed=get_embed(event))
await webhook.send(content=f"<@&{EVENTS_ROLE_ID}>{mentions}", embed=get_embed(event))
18 changes: 14 additions & 4 deletions micro/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
load_dotenv()

import discord
from discord.ext import commands

from classes.views import ModerationView, ResourcesView, RoleView, IssueListView
from classes.database import Database
import datetime
from discord.ext import commands, tasks

from views import (
ModerationView,
ResourcesView,
RoleView,
IssueListView
)
from classes import Database
from logger import logger
from static.paths import COGS_DIR
from static.constants import EVENTS_CHANNEL, NEXT_EVENT_CHANNEL, MEMBERCOUNT_CHANNEL
from API import app

from logging import Logger
Expand Down Expand Up @@ -58,6 +65,9 @@ async def create_pool(self, dsn):

return msg

async def on_ready(self):
members_ch = self.get_channel(MEMBERCOUNT_CHANNEL)
await members_ch.edit(name=f"Member Count: {len(self.users)}")

# Init logger
logger = logger()
Expand Down
7 changes: 7 additions & 0 deletions micro/classes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .database import Database
from .bad_words import BadWords
from .github import GitHub
from .question_query import QuestionQuery
from .resources import Resources
from .colored_embed import CEmbed
from .paginator import Paginator
2 changes: 1 addition & 1 deletion micro/classes/badWords.py → micro/classes/bad_words.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self,logger):
self.logger = logger
self.insults = get_insult_list()

def isItInsult(self, msg_lst):
def is_it_insult(self, msg_lst):
try:
msg = ' '.join(msg_lst)

Expand Down
12 changes: 5 additions & 7 deletions micro/classes/github.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os, requests, discord
import os, requests

from typing import Iterable
from math import ceil
from github import Github, Issue, PaginatedList
from github import Github, Issue
from github.GithubException import UnknownObjectException, BadCredentialsException


Expand Down Expand Up @@ -78,14 +78,12 @@ def get_issue(self, num: int) -> Issue.Issue | None:
return issue

def list_issues(
self, paginate: bool
) -> PaginatedList.PaginatedList | list[list] | None:
self
) -> list[Issue.Issue] | None:
"""Returns the list of issues of the repo, or the paginated list of issue"""
if not self.repo:
return
issues = self.repo.get_issues()
if paginate:
return self.prepare_pagination(issues)
issues = list(self.repo.get_issues()) # Convert a PaginatedList into a normal list of the issues
return issues

def create_issue(
Expand Down
34 changes: 34 additions & 0 deletions micro/classes/paginator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Paginator:
def __init__(self, items: list, page_size: int):
self.items = items
self.page_size = page_size
self.curr_page = 1 # For user-end
self.curr_index = 0 # For back-end
self.total_pages = len(self.items) // self.page_size + 1 # For user-end as well

def get_page(self) -> list:
"""
Returns the items of the current page
"""
return self.items[self.curr_index:self.curr_index+self.page_size]

def next_page(self) -> list | None:
"""
Returns the items of the next page (None if there is no next page)
"""
if self.curr_index + self.page_size < len(self.items):
self.curr_index += self.page_size
self.curr_page += 1
return self.get_page()
# No next page
return None

def prev_page(self) -> list | None:
"""
Returns the items of the previous page (None if there is no previous page)
"""
if self.curr_index - self.page_size >= 0:
self.curr_index -= self.page_size
self.curr_page -= 1
return self.get_page()
return None
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def question(self, command):
title, msg = self.data['Title']['who'], self.data['Answer']['who']
if command in self.data['Answer'].keys():
title, msg = self.data['Title'][command], self.data['Answer'][command]
return self._toEmbed(title, msg)
return self._toembed(title, msg)

def _toEmbed(self, title, msg):
def _toembed(self, title, msg):
try:
return embeds.Embed.from_dict(
{
Expand Down
Loading