Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 10 additions & 15 deletions src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

# define class for IFV modals
class IFVSelectionModal(discord.ui.DesignerModal):
def __init__(self, user_id:int, action:str, options_data:list, *args, **kwargs) -> None:
def __init__(self, user_id:int, action:str, options_data:list[classes.ifv.IFV], *args, **kwargs) -> None:
"""Create an IFVSelectionModal object, for selecting and modifying IFV details."""
super().__init__(*args, **kwargs) # pass args and kwargs to base class
logger.debug('Args and kwargs passed to base Modal')
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(self, user_id:int, action:str, options_data:list, *args, **kwargs)

logger.debug('Modal initialized')

async def callback(self, interaction):
async def callback(self, interaction:discord.Interaction) -> None:
"""Callback for an IFVSelectionModal."""
success = discord.Embed(description = "IFV modified successfully!").set_footer(text = 'The queue embed may take 1-5 seconds to refresh.')
failure_invalid_url = discord.Embed(description = "IFV was not modified.").set_footer(text = 'Please provide a link that is a valid URL.')
Expand Down Expand Up @@ -143,12 +143,12 @@ async def callback(self, interaction):

# define class for IFV view
class IFVView(discord.ui.View):
def __init__(self, council:int, *args, **kwargs):
def __init__(self, council:int, *args, **kwargs) -> None:
super().__init__(*args, **kwargs) # pass args and kwargs to base class
logger.debug('Args and kwargs passed to base Modal')

self.council = council
async def _button(self, button, interaction):
async def _button(self, button:discord.ui.Button, interaction:discord.Interaction) -> None:
"""Private method to handle button callbacks."""
action = button.custom_id # redefine some basic information
user_id = interaction.user.id
Expand All @@ -170,15 +170,15 @@ async def _button(self, button, interaction):
logger.info('Modal submitted, embed refreshed')

@discord.ui.button(label="Accept IFV", style=discord.ButtonStyle.success, custom_id='accept') # accept IFV button
async def accept(self, button:discord.ui.Button, interaction:discord.Interaction): # pass onto _button handler
async def accept(self, button:discord.ui.Button, interaction:discord.Interaction) -> None: # pass onto _button handler
await self._button(button, interaction)

@discord.ui.button(label="Submit IFV", style=discord.ButtonStyle.primary, custom_id='submit') # submit IFV button
async def submit(self, button:discord.ui.Button, interaction:discord.Interaction): # pass onto _button handler
async def submit(self, button:discord.ui.Button, interaction:discord.Interaction) -> None: # pass onto _button handler
await self._button(button, interaction)

@discord.ui.button(label="Remove IFV", style=discord.ButtonStyle.danger, custom_id='remove') # remove IFV button
async def remove(self, button:discord.ui.Button, interaction:discord.Interaction): # pass onto _button handler
async def remove(self, button:discord.ui.Button, interaction:discord.Interaction) -> None: # pass onto _button handler
await self._button(button, interaction)


Expand Down Expand Up @@ -241,7 +241,7 @@ async def _fetch_proposals() -> None:
logger.info('Proposal thread being created')
logger.info('Proposal data parsed and stored')

async def _new_sse_event(payload:str):
async def _new_sse_event(payload:str) -> None:
logger.debug('New SSE event received, checking proposals...')
await _fetch_proposals()

Expand Down Expand Up @@ -322,11 +322,6 @@ async def _get_queue_embed(council:int) -> discord.Embed:
emoji = '🔴'
else:
emoji = '🟢'

'''if len(reactions) == 2: # this was needed once... but then a bug magically resolved itself. leaving here just in case.
emoji = '🟢/🔴'
else:
emoji = reactions[0].emoji'''

logger.debug('Proposal information formatted')

Expand All @@ -345,7 +340,7 @@ async def _get_queue_embed(council:int) -> discord.Embed:
logger.info('Embed object created')
return embed # return it

async def _show_queue(ctx: discord.ApplicationContext, council:int):
async def _show_queue(ctx: discord.ApplicationContext, council:int) -> None:
if await _check_perms(ctx, 'user'):
await ctx.defer(ephemeral = True)
logger.info('Fetching queue embed')
Expand All @@ -361,7 +356,7 @@ async def _show_queue(ctx: discord.ApplicationContext, council:int):
await ctx.respond(embed = embed, ephemeral = True)
logger.info('Error embed sent')

async def _announce_queue(ctx: discord.ApplicationContext, council:int, ping_users:bool):
async def _announce_queue(ctx: discord.ApplicationContext, council:int, ping_users:bool) -> None:
if await _check_perms(ctx, 'admin'):
await ctx.defer() # the deferral must be here so the 'No Permissions' embed can be sent ephemerally
logger.info('Fetching queue embed')
Expand Down
31 changes: 8 additions & 23 deletions src/classes/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,25 @@
from .exceptions import *
import logging

class Permission:

class DiscordObject:
def __init__(self):
self.initialized = False
def fromAttributeValues(self, kind:str, identifier:int):
self.kind = kind
self.identifier = identifier
self.initialized = True
return self
def fromSQLValues(self, values:tuple):
def fromSQLValues(self, values:tuple[str, int]):
self.kind = values[0]
self.identifier = values[1]
self.initialized = True
return self
def toSQLValues(self):
def toSQLValues(self) -> tuple[str, int]:
if self.initialized:
return (self.kind, self.identifier)
else:
raise exceptions.UninitializedException()
class Permission(DiscordObject):
pass

class Channel:
def __init__(self):
self.initialized = False
def fromAttributeValues(self, kind:str, identifier:int):
self.kind = kind
self.identifier = identifier
self.initialized = True
return self
def fromSQLValues(self, values:tuple):
self.kind = values[0]
self.identifier = values[1]
self.initialized = True
return self
def toSQLValues(self):
if self.initialized:
return (self.kind, self.identifier)
else:
raise exceptions.UninitializedException()
class Channel(DiscordObject):
pass
8 changes: 3 additions & 5 deletions src/classes/ifv.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@
class IFV:
def __init__(self):
self.initialized = False
def fromAttributeValues(self, id:str, name:str, thread = None, ifvauthor = None, ifvlink = None):
def fromAttributeValues(self, id:str, name:str, thread:str | None = None, ifvauthor:str | None = None, ifvlink:str | None = None):
self.id = id
self.name = name
self.thread = thread
self.ifvauthor = ifvauthor
self.ifvlink = ifvlink
self.initialized = True
return self
def fromSQLValues(self, values:tuple):
def fromSQLValues(self, values:tuple[str, str, str | None, str | None, str | None]):
self.id = values[0]
self.name = values[1]
self.thread = values[2]
self.ifvauthor = values[3]
self.ifvlink = values[4]
self.initialized = True
return self
def toSQLValues(self):
def toSQLValues(self) -> tuple[str, str, str, str | None, str | None, str | None]:
if self.initialized:
return (self.id,self.name,self.thread,self.ifvauthor,self.ifvlink)
else:
Expand Down
8 changes: 3 additions & 5 deletions src/classes/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class Event:
def __init__(self):
self.initialized = False
def fromAttributeValues(self, event:int, time:int, category:str, data:list, actor = None, receptor = None, origin = None, destination = None):
def fromAttributeValues(self, event:int, time:int, category:str, data:list, actor: str | None = None, receptor:str | None = None, origin:str | None = None, destination:str | None = None):
self.event = event
self.time = time
self.actor = actor
Expand All @@ -29,8 +29,7 @@ def fromAttributeValues(self, event:int, time:int, category:str, data:list, acto
self.category = category
self.data = data
self.initialized = True
return self
def fromSQLValues(self, values:tuple):
def fromSQLValues(self, values:tuple[int, int, str, list, str | None, str | None, str | None, str | None]):
self.event = values[0]
self.time = values[1]
self.actor = values[2]
Expand All @@ -40,8 +39,7 @@ def fromSQLValues(self, values:tuple):
self.category = values[6]
self.data = values[7]
self.initialized = True
return self
def toSQLValues(self):
def toSQLValues(self) -> tuple[int, int, str, list, str | None, str | None, str | None, str | None]:
if self.initialized:
return (self.event,self.time,self.actor,self.receptor,self.origin,self.destination,self.category,self.data)
else:
Expand Down
8 changes: 3 additions & 5 deletions src/classes/wa.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Proposal:
def __init__(self):
self.initialized = False
def fromAttributeValues(self, id:str, council:int, name:str, category:str, author:str, legal:bool, quorum:bool, coauthors=[]):
def fromAttributeValues(self, id:str, council:int, name:str, category:str, author:str, legal:bool, quorum:bool, coauthors:list[str | None] = []):
self.id = id
self.council = council
self.name = name
Expand All @@ -31,8 +31,7 @@ def fromAttributeValues(self, id:str, council:int, name:str, category:str, autho
self.legal = legal
self.quorum = quorum
self.initialized = True
return self
def fromSQLValues(self, values:tuple):
def fromSQLValues(self, values:tuple[str, int, str, str, str, bool, bool, list[str | None]]):
self.id = values[0]
self.council = values[1]
self.name = values[2]
Expand All @@ -42,8 +41,7 @@ def fromSQLValues(self, values:tuple):
self.legal = values[6]
self.quorum = values[7]
self.initialized = True
return self
def toSQLValues(self):
def toSQLValues(self) -> tuple[str, int, str, str, str, bool, bool, list[str | None]]:
if self.initialized:
return (self.id,self.council,self.name,self.category,self.author,self.coauthors,self.legal,self.quorum)
else:
Expand Down
20 changes: 10 additions & 10 deletions src/customio/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def setup_all(self) -> None:
self.connection_self.connection_pool.check()
async def cleanup(self) -> None:
await self._close_connection_pool()
async def listen_for_new_sse_events(self,callback) -> None:
async def listen_for_new_sse_events(self,callback:function) -> None:
"""Add a listener that calls callback on all new SSE events"""
try:
async with self.connection_pool.connection() as conn:
Expand All @@ -88,7 +88,7 @@ async def listen_for_new_sse_events(self,callback) -> None:
self.connection_self.connection_pool.check()
except asyncio.CancelledError:
self.logger.debug('Listener cancelled')
async def get_by_event(self, event:int):
async def get_by_event(self, event:int) -> classes.sse.Event:
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
self.logger.debug('DB connection opened from pool')
Expand Down Expand Up @@ -151,7 +151,7 @@ async def nsqueue_get_by_id(self, id:str) -> classes.wa.Proposal:
return proposal
except psycopg_pool.PoolTimeout:
self.connection_self.connection_pool.check()
async def nsqueue_get_all_legal_by_council_limited(self, council = 1, limit = 7) -> list:
async def nsqueue_get_all_legal_by_council_limited(self, council:int = 1, limit:int = 7) -> list[classes.wa.Proposal]:
"""Get all proposals that are legal from the NSQueue, up to the specified limit"""
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
Expand Down Expand Up @@ -233,7 +233,7 @@ async def ifvqueue_get_by_id(self, id:str) -> classes.ifv.IFV:
return ifv
except psycopg_pool.PoolTimeout:
self.connection_self.connection_pool.check()
async def ifvqueue_get_by_author(self, author:int) -> list:
async def ifvqueue_get_by_author(self, author:int) -> list[classes.ifv.IFV]:
"""Get all IFVs from the IFVQueue with the specified author"""
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
Expand All @@ -254,7 +254,7 @@ async def ifvqueue_get_by_author(self, author:int) -> list:
return ifvs
except psycopg_pool.PoolTimeout:
self.connection_self.connection_pool.check()
async def ifvqueue_get_unauthored_limited(self,limit = 7) -> list:
async def ifvqueue_get_unauthored_limited(self,limit:int = 7) -> list[classes.ifv.IFV]:
"""Get all IFVs from the IFVQueue with no author"""
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
Expand Down Expand Up @@ -308,7 +308,7 @@ async def ifvqueue_update_link_by_id(self, id:str, link:str) -> None:
await conn.commit()
except psycopg_pool.PoolTimeout:
self.connection_self.connection_pool.check()
async def ifvqueue_remove_author_link(self, id:str):
async def ifvqueue_remove_author_link(self, id:str) -> None:
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
self.logger.debug('DB connection opened from pool')
Expand All @@ -323,7 +323,7 @@ async def ifvqueue_remove_author_link(self, id:str):
except psycopg_pool.PoolTimeout:
self.connection_self.connection_pool.check()
# BotPerms table
async def botperms_add(self, permission:classes.auth.Permission):
async def botperms_add(self, permission:classes.auth.Permission) -> None:
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
self.logger.debug('DB connection opened from pool')
Expand All @@ -337,7 +337,7 @@ async def botperms_add(self, permission:classes.auth.Permission):
await conn.commit()
except psycopg_pool.PoolTimeout:
self.connection_self.connection_pool.check()
async def botperms_get_by_kind(self, kind:str):
async def botperms_get_by_kind(self, kind:str) -> classes.auth.Permission:
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
self.logger.debug('DB connection opened from pool')
Expand All @@ -352,7 +352,7 @@ async def botperms_get_by_kind(self, kind:str):
return permission_object
except psycopg_pool.PoolTimeout:
self.connection_self.connection_pool.check()
async def channelref_add(self, channel:classes.auth.Channel):
async def channelref_add(self, channel:classes.auth.Channel) -> None:
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
self.logger.debug('DB connection opened from pool')
Expand All @@ -366,7 +366,7 @@ async def channelref_add(self, channel:classes.auth.Channel):
await conn.commit()
except psycopg_pool.PoolTimeout:
self.connection_self.connection_pool.check()
async def channelref_get_by_kind(self, kind:str):
async def channelref_get_by_kind(self, kind:str) -> classes.auth.Channel:
try:
async with self.connection_pool.connection() as conn: # get a connection from the pool
self.logger.debug('DB connection opened from pool')
Expand Down
6 changes: 3 additions & 3 deletions src/customio/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# set up a logger
logger = logging.getLogger('assembly.customio.env') # get the logger for this script

def load_secrets_from_envvars():
def load_secrets_from_envvars() -> tuple[str, str]:
# load envvars
token_file = str(os.getenv("ASSEMBLY_TOKEN_FILE"))
pgpass_file = str(os.getenv("POSTGRES_PASSWORD_FILE"))
Expand All @@ -44,14 +44,14 @@ def load_secrets_from_envvars():
pgpass = file.read()
return token, pgpass

def load_database_config_from_envvars():
def load_database_config_from_envvars() -> tuple[str, str, str, str, str]:
user = str(os.getenv("POSTGRES_USER"))
host = str(os.getenv("POSTGRES_HOST"))
port = str(os.getenv("POSTGRES_PORT"))
assembly_db = str(os.getenv("POSTGRES_ASSEMBLY_DB"))
akari_db = str(os.getenv("POSTGRES_AKARI_DB"))
return user, host, port, assembly_db, akari_db

def load_useragent_from_envvars():
def load_useragent_from_envvars() -> str:
useragent_nation = str(os.getenv("NS_USER_AGENT"))
return useragent_nation
Loading
Loading