Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit cd2ad4c

Browse files
authored
Merge pull request #15 from DirectiveAthena/v0.7.0
V0.7.0
2 parents d8f0c58 + a8adb60 commit cd2ad4c

25 files changed

+691
-310
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,21 @@ class newBot(AthenaTwitchBot.TwitchBot):
4141
# - Command -
4242
# A command is only ran when it is invoked by a user in chat
4343
# In the following case this would be by typing "!ping" in chat
44-
@AthenaTwitchBot.command_method(name="ping")
44+
@AthenaTwitchBot.TwitchBotMethod.command(names="ping")
4545
def command_ping(self, context: AthenaTwitchBot.TwitchContext):
46-
context.reply("pong!") # a "context.reply" function will reply to the user whi invoked the command
46+
context.reply("pong!") # a "context.reply" function will reply to the user who invoked the command
4747

4848
# - Task -
4949
# A task is run automatically every "delay" amount of seconds
5050
# In the following case, the method will be run every minute
51-
# The "wait_before" kwarg defines if the asyncio.sleep runs before or after the first call of the callback
52-
@AthenaTwitchBot.scheduled_task_method(delay=60, wait_before=True)
51+
# The "call_on_startup" kwarg defines if the task has to be run on bot startup
52+
@AthenaTwitchBot.TwitchBotMethod.scheduled_task(interval=AthenaLib.models.Minute(1), call_on_startup=True)
5353
def task_post_github(self, context: AthenaTwitchBot.TwitchContext):
5454
context.write(f"This bot is made possible by: https://github.com/DirectiveAthena/AthenaTwitchBot")
5555

5656
# --- Main function ---
5757
def main():
58+
# the launch function handles everything about the protocol setup and command handling
5859
AthenaTwitchBot.launch(
5960
bot=newBot(),
6061
ssl=True # set to true to enable ssl connection to Twitch
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# ----------------------------------------------------------------------------------------------------------------------
44
# General Packages
55
from __future__ import annotations
6-
from dataclasses import dataclass
7-
from typing import Callable
86

97
# Custom Library
108

@@ -13,9 +11,3 @@
1311
# ----------------------------------------------------------------------------------------------------------------------
1412
# - Code -
1513
# ----------------------------------------------------------------------------------------------------------------------
16-
@dataclass(kw_only=True, match_args=True, slots=True)
17-
class Command:
18-
name:str
19-
case_sensitive:bool
20-
callback:Callable
21-
args_enabled:bool

Tests/models/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ----------------------------------------------------------------------------------------------------------------------
2+
# - Package Imports -
3+
# ----------------------------------------------------------------------------------------------------------------------
4+
# General Packages
5+
from __future__ import annotations
6+
7+
# Custom Library
8+
9+
# Custom Packages
10+
11+
# ----------------------------------------------------------------------------------------------------------------------
12+
# - Code -
13+
# ----------------------------------------------------------------------------------------------------------------------
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# ----------------------------------------------------------------------------------------------------------------------
2+
# - Package Imports -
3+
# ----------------------------------------------------------------------------------------------------------------------
4+
# General Packages
5+
from __future__ import annotations
6+
import unittest
7+
8+
# Custom Library
9+
from AthenaTwitchBot.models.twitch_bot_method import TwitchBotMethod
10+
from AthenaTwitchBot.models.twitch_channel import TwitchChannel
11+
12+
# Custom Packages
13+
from Tests.support import EmptyBot
14+
15+
# ----------------------------------------------------------------------------------------------------------------------
16+
# - Support Code -
17+
# ----------------------------------------------------------------------------------------------------------------------
18+
class TestBot_0(EmptyBot):
19+
@TwitchBotMethod().command(names="help")
20+
def command_help(self):
21+
return "not helping"
22+
23+
class TestBot_1(EmptyBot):
24+
def __init__(self):
25+
self.name = "TestBot_1"
26+
super(TestBot_1, self).__init__()
27+
28+
@TwitchBotMethod(channels=["some_channel"]).command(names="help")
29+
def command_help(self):
30+
return f"{self.name}"
31+
32+
class TestBot_2(EmptyBot):
33+
@TwitchBotMethod.command(names="help")
34+
def command_help(self):
35+
return "not helping"
36+
37+
# ----------------------------------------------------------------------------------------------------------------------
38+
# - Code -
39+
# ----------------------------------------------------------------------------------------------------------------------
40+
class Test_TwitchBotMethod(unittest.TestCase):
41+
def test_Bot0(self):
42+
test_bot0 = TestBot_0()
43+
44+
self.assertEqual(
45+
[],
46+
test_bot0.command_help.channels
47+
)
48+
49+
self.assertEqual(
50+
"not helping",
51+
test_bot0.command_help.callback()
52+
)
53+
54+
def test_Bot1(self):
55+
test_bot1 = TestBot_1()
56+
self.assertEqual(
57+
[TwitchChannel("some_channel")],
58+
test_bot1.command_help.channels
59+
)
60+
self.assertIs(
61+
test_bot1,
62+
test_bot1.command_help.owner
63+
)
64+
self.assertEqual(
65+
test_bot1.name,
66+
test_bot1.command_help.callback()
67+
)
68+
69+
def test_Bot2(self):
70+
test_bot2 = TestBot_2()
71+
self.assertEqual(
72+
[],
73+
test_bot2.command_help.channels
74+
)
75+

Tests/support.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ----------------------------------------------------------------------------------------------------------------------
2+
# - Package Imports -
3+
# ----------------------------------------------------------------------------------------------------------------------
4+
# General Packages
5+
from __future__ import annotations
6+
7+
# Custom Library
8+
from AthenaTwitchBot.models.twitch_bot import TwitchBot
9+
10+
# Custom Packages
11+
12+
# ----------------------------------------------------------------------------------------------------------------------
13+
# - Support Code -
14+
# ----------------------------------------------------------------------------------------------------------------------
15+
class EmptyBot(TwitchBot):
16+
def __init__(self):
17+
super(EmptyBot, self).__init__(
18+
nickname="empty_bot",
19+
oauth_token="...",
20+
channels=["directiveathena"],
21+
prefix="!",
22+
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def readme_handler() -> str:
1818

1919
def version_handler() -> str:
2020
# ------------------------------------------------------------------------------------------------------------------
21-
version = 0,6,1 # <-- DEFINE THE VERSION IN A TUPLE FORMAT HERE
21+
version = 0,7,0 # <-- DEFINE THE VERSION IN A TUPLE FORMAT HERE
2222
# ------------------------------------------------------------------------------------------------------------------
2323
version_str = ".".join(str(i) for i in version)
2424

src/AthenaTwitchBot/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# ----------------------------------------------------------------------------------------------------------------------
22
# - Package Imports -
33
# ----------------------------------------------------------------------------------------------------------------------
4-
from AthenaTwitchBot.decorators.command import command_method
5-
from AthenaTwitchBot.decorators.scheduled_task import scheduled_task_method
6-
74
from AthenaTwitchBot.models.twitch_bot import TwitchBot
85
from AthenaTwitchBot.models.twitch_bot_protocol import TwitchBotProtocol
96
from AthenaTwitchBot.models.twitch_context import TwitchContext
7+
from AthenaTwitchBot.models.twitch_bot_method import TwitchBotMethod
108

119
from AthenaTwitchBot.functions.launch import launch
1210

src/AthenaTwitchBot/data/dict_mapping_logic.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,29 @@
1414
# - Code -
1515
# ----------------------------------------------------------------------------------------------------------------------
1616
MESSAGE_TAG_MAPPING:dict[str:Callable] = {
17-
"@badge-info": "badge_info",
18-
"badges": "badges",
19-
"client-nonce": "client_nonce",
20-
"color": "color",
21-
"display-name": "display_name",
22-
"emotes": "emotes",
23-
"first-msg": "first_msg",
24-
"flags": "flags",
25-
"id": "message_id",
26-
"mod": "mod",
27-
"room-id": "room_id",
28-
"subscriber": "subscriber",
29-
"tmi-sent-ts": "tmi_sent_ts",
30-
"turbo": "turbo",
31-
"user-id": "user_id",
32-
"user-type": "user_type",
33-
"reply-parent-display-name": "reply_parent_display_name",
34-
"reply-parent-msg-body": "reply_parent_msg_body",
35-
"reply-parent-msg-id": "reply_parent_msg_id",
36-
"reply-parent-user-id": "reply_parent_user_id",
37-
"reply-parent-user-login": "reply_parent_user_login",
38-
"emote-only": "emote_only",
17+
"@badge-info": "badge_info",
18+
"badges": "badges",
19+
"client-nonce": "client_nonce",
20+
"color": "color",
21+
"display-name": "display_name",
22+
"emotes": "emotes",
23+
"first-msg": "first_msg",
24+
"flags": "flags",
25+
"id": "message_id",
26+
"mod": "mod",
27+
"room-id": "room_id",
28+
"subscriber": "subscriber",
29+
"tmi-sent-ts": "tmi_sent_ts",
30+
"turbo": "turbo",
31+
"user-id": "user_id",
32+
"user-type": "user_type",
33+
"reply-parent-display-name": "reply_parent_display_name",
34+
"reply-parent-msg-body": "reply_parent_msg_body",
35+
"reply-parent-msg-id": "reply_parent_msg_id",
36+
"reply-parent-user-id": "reply_parent_user_id",
37+
"reply-parent-user-login": "reply_parent_user_login",
38+
"emote-only": "emote_only",
39+
"returning-chatter": "returning_chatter"
3940
}
4041

4142
MESSAGE_TAG_CONVERSION_MAPPING:dict[str:Callable] = {
@@ -57,8 +58,9 @@
5758
"user-type": lambda value: value,
5859
"reply-parent-display-name":lambda value: value,
5960
"reply-parent-msg-body": lambda value: value,
60-
"reply-parent-msg-id": lambda value: int(value),
61+
"reply-parent-msg-id": lambda value: value,
6162
"reply-parent-user-id": lambda value: int(value),
6263
"reply-parent-user-login": lambda value: value,
6364
"emote-only": lambda value: bool(int(value)),
65+
"returning-chatter": lambda value: bool(int(value)),
6466
}

0 commit comments

Comments
 (0)