Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# - Code -
# ----------------------------------------------------------------------------------------------------------------------
def version_handler() -> str:
version = 0,1,0
version = 0,1,1
version_str = ".".join(str(i) for i in version)

with open("src/AthenaTwitchBot/_info/_v.py", "w") as file:
Expand Down
4 changes: 2 additions & 2 deletions src/AthenaTwitchBot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ----------------------------------------------------------------------------------------------------------------------
# - Package Imports -
# ----------------------------------------------------------------------------------------------------------------------
from AthenaTwitchBot.decorators.command import commandmethod
from AthenaTwitchBot.decorators.frequentoutput import frequentoutputmethod
from AthenaTwitchBot.decorators.command import command_method
from AthenaTwitchBot.decorators.frequentoutput import frequent_output_method

from AthenaTwitchBot.models.twitch_bot import TwitchBot
from AthenaTwitchBot.models.twitch_bot_protocol import TwitchBotProtocol
Expand Down
2 changes: 1 addition & 1 deletion src/AthenaTwitchBot/_info/_v.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def _version():
return '0.1.0'
return '0.1.1'
2 changes: 1 addition & 1 deletion src/AthenaTwitchBot/decorators/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ----------------------------------------------------------------------------------------------------------------------
# - Code -
# ----------------------------------------------------------------------------------------------------------------------
def commandmethod(name:str):
def command_method(name:str):
def decorator(fnc):
def wrapper(*args, **kwargs):
return fnc(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions src/AthenaTwitchBot/decorators/frequentoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ----------------------------------------------------------------------------------------------------------------------
# - Code -
# ----------------------------------------------------------------------------------------------------------------------
def frequentoutputmethod(delay:int=3600): # defult is every hour
def frequent_output_method(delay:int=3600): # default is every hour
"""
Create a method that runs every couple of seconds.
The delay parameter is defined in seconds
Expand All @@ -25,7 +25,7 @@ def wrapper(*args, **kwargs):

# store attributes for later use by the bot
# to be used by the protocol to assign it top an async call loop
wrapper.is_frequent_ouput = True
wrapper.is_frequent_output = True # typo caught by NoirPi
wrapper.delay = delay
return wrapper
return decorator
1 change: 0 additions & 1 deletion src/AthenaTwitchBot/functions/twitch_irc_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# ----------------------------------------------------------------------------------------------------------------------
# General Packages
from __future__ import annotations
import asyncio

# Custom Library

Expand Down
14 changes: 6 additions & 8 deletions src/AthenaTwitchBot/functions/twitch_message_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# General Packages
from __future__ import annotations
from typing import Callable
from datetime import datetime
import time

# Custom Library
from AthenaColor import StyleNest, ForeNest, HEX
Expand Down Expand Up @@ -71,13 +69,13 @@ def twitch_message_constructor_tags(message_bytes:bytearray, bot_name:str) -> Tw
# with tags enabled, we know that the first element of the list above contains all the user's tags
# This enables us to loop them and assign them to the message
# This is done to make them accessible to the command parsing
# The second part of the split message is the user definement. The user id is found in the tags
# The second part of the split message is the user definition. The user id is found in the tags
# IRC message string is found next
# The channel from which it is sent is also recieved.
# When the bot is only installed in one channel, this isn't usefull, but if a bot is used in multiple channels
# this is part of the usefull known context
# The channel from which it is sent is also received.
# When the bot is only installed in one channel, this isn't useful, but if a bot is used in multiple channels
# this is part of the usefully known context
# Finally all text should be clumped together again, to be searched though for a custom command
# This is to be done by the protocol class, not the message constructir
# This is to be done by the protocol class, not the message constructor

tags, user, irc_message, channel, *text = content
twitch_message:TwitchMessage = TwitchMessage(
Expand All @@ -95,7 +93,7 @@ def twitch_message_constructor_tags(message_bytes:bytearray, bot_name:str) -> Tw
try:
TAG_MAPPING[tag_name](tm=twitch_message,tag_value=tag_value)
except KeyError:
print(StyleNest.Bold(ForeNest.Maroon(f"Unkown tag of '{tag_name}' found. Please create a bug report on the git repo")))
print(StyleNest.Bold(ForeNest.Maroon(f"Unknown tag of '{tag_name}' found. Please create a bug report on the git repo")))
pass

return twitch_message
13 changes: 5 additions & 8 deletions src/AthenaTwitchBot/models/twitch_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
# ----------------------------------------------------------------------------------------------------------------------
# General Packages
from __future__ import annotations
import asyncio
from dataclasses import dataclass, field, InitVar
from typing import Callable
import inspect

# Custom Library
import AthenaLib
import AthenaColor

# Custom Packages

Expand All @@ -25,9 +22,9 @@ class TwitchBot:
prefix:str

# Twitch-specific capabilities : https://dev.twitch.tv/docs/irc/capabilities
twitch_capibility_commands:bool=False
twitch_capibility_membership:bool=False
twitch_capibility_tags:bool=True # only one that has the default set to true, as this is required to make reply's work
twitch_capability_commands:bool=False
twitch_capability_membership:bool=False
twitch_capability_tags:bool=True # only one that has the default set to true, as this is required to make reply's work

predefined_commands:InitVar[dict[str: Callable]]=None # made part of init if someone wants to feel the pain of adding commands manually

Expand All @@ -49,12 +46,12 @@ def __new__(cls, *args, **kwargs):
# Which is to be used in the commands tuple
obj = super(TwitchBot, cls).__new__(cls,*args,**kwargs)

# loop over the bot's metods and parse the different methods
# loop over the bots methods and parse the different methods
for k,v in cls.__dict__.items():
if inspect.isfunction(v):
if "is_command" in (attributes := [attribute for attribute in dir(v) if not attribute.startswith("__")]):
cls.commands[v.command_name] = v
elif "is_frequent_ouput" in attributes:
elif "is_frequent_output" in attributes:
cls.frequent_outputs.append((v,v.delay))

return obj
Expand Down
8 changes: 4 additions & 4 deletions src/AthenaTwitchBot/models/twitch_bot_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class TwitchBotProtocol(asyncio.Protocol):
message_constructor:Callable = field(init=False)

def __post_init__(self):
if self.bot.twitch_capibility_tags:
if self.bot.twitch_capability_tags:
self.message_constructor = twitch_message_constructor_tags
else:
raise NotImplementedError("This needs to be created")

# ----------------------------------------------------------------------------------------------------------------------
# - Protocol neseccary -
# - Protocol necessary -
# ----------------------------------------------------------------------------------------------------------------------
def connection_made(self, transport: asyncio.transports.Transport) -> None:
self.transport = transport
Expand All @@ -47,7 +47,7 @@ def connection_made(self, transport: asyncio.transports.Transport) -> None:
self.transport.write(messages.join(channel=self.bot.channel))
self.transport.write(messages.request_tags)

# add frequent_ouput methods to the coroutine loop
# add frequent_output methods to the coroutine loop
loop = asyncio.get_running_loop()
for callback, delay in self.bot.frequent_outputs:
coro = loop.create_task(self.frequent_output_call(callback,delay))
Expand Down Expand Up @@ -82,7 +82,7 @@ def data_received(self, data: bytearray) -> None:
self.bot.commands[user_cmd](
self=self.bot,
# Assign a context so the user doesn't need to write the transport messages themselves
# A user opnly has to write the text
# A user only has to write the text
context=TwitchMessageContext(
message=twitch_message,
transport=self.transport
Expand Down
2 changes: 1 addition & 1 deletion src/AthenaTwitchBot/models/twitch_bot_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@dataclass(slots=True,eq=False,order=False,kw_only=True)
class Server:
bot: TwitchBot
socket:socket.socket=None
socket:socket.socket=field(default_factory=socket.socket)

# non init slots
server:asyncio.AbstractServer = field(init=False)
Expand Down
3 changes: 1 addition & 2 deletions src/AthenaTwitchBot/models/twitch_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# General Packages
from __future__ import annotations
from dataclasses import dataclass, field
from datetime import datetime

# Custom Library
from AthenaColor import HEX
Expand All @@ -18,7 +17,7 @@

@dataclass(slots=True, eq=True, match_args=True)
class TwitchMessage:
message:str=EMPTY_STR # complete message without the sufix: "\r\n"
message:str=EMPTY_STR # complete message without the suffix: "\r\n"
message_type:str=EMPTY_STR
channel:str=EMPTY_STR
text:str=EMPTY_STR
Expand Down