Skip to content

Commit 0d3cb67

Browse files
authored
Merge pull request game-by-virtuals#98 from game-by-virtuals/chore/yang-clean-up-telegram-plugin
[Chore] Clean Up Telegram Plugin
2 parents ba6df0f + 87bde7e commit 0d3cb67

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

plugins/telegram/examples/test_telegram_game_functions.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import os
2-
import sys
31
from typing import Tuple
42

5-
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..'))
6-
sys.path.append(project_root)
7-
8-
from plugins.telegram.telegram_plugin_gamesdk.telegram_plugin import TelegramPlugin
9-
from src.game_sdk.game.custom_types import Function, FunctionResultStatus, Argument
3+
from game_sdk.game.custom_types import Function, FunctionResultStatus, Argument
4+
from telegram_plugin_gamesdk.telegram_plugin import TelegramPlugin
105

116

127
def send_message_executable(tg_plugin: TelegramPlugin, chat_id: str, text: str) -> Tuple[FunctionResultStatus, str, dict]:
@@ -16,6 +11,7 @@ def send_message_executable(tg_plugin: TelegramPlugin, chat_id: str, text: str)
1611
except Exception as e:
1712
return FunctionResultStatus.FAILED, str(e), {}
1813

14+
1915
def send_message_fn(bot: TelegramPlugin) -> Function:
2016
return Function(
2117
fn_name="send_message",
@@ -27,13 +23,15 @@ def send_message_fn(bot: TelegramPlugin) -> Function:
2723
executable=lambda chat_id, text: send_message_executable(bot, chat_id, text),
2824
)
2925

26+
3027
def send_media_executable(tg_plugin: TelegramPlugin, chat_id: str, media_type: str, media: str, caption: str = None) -> Tuple[FunctionResultStatus, str, dict]:
3128
try:
3229
tg_plugin.send_media(chat_id=chat_id, media_type=media_type, media=media, caption=caption)
3330
return FunctionResultStatus.DONE, "Media sent successfully", {}
3431
except Exception as e:
3532
return FunctionResultStatus.FAILED, str(e), {}
3633

34+
3735
def send_media_fn(bot: TelegramPlugin) -> Function:
3836
return Function(
3937
fn_name="send_media",
@@ -47,13 +45,15 @@ def send_media_fn(bot: TelegramPlugin) -> Function:
4745
executable=lambda chat_id, media_type, media, caption=None: send_media_executable(bot, chat_id, media_type, media, caption),
4846
)
4947

48+
5049
def create_poll_executable(tg_plugin: TelegramPlugin, chat_id: str, question: str, options: list[str], is_anonymous: bool = True, allows_multiple_answers: bool = False) -> Tuple[FunctionResultStatus, str, dict]:
5150
try:
5251
tg_plugin.create_poll(chat_id=chat_id, question=question, options=options, is_anonymous=is_anonymous, allows_multiple_answers=allows_multiple_answers)
5352
return FunctionResultStatus.DONE, "Poll created successfully", {}
5453
except Exception as e:
5554
return FunctionResultStatus.FAILED, str(e), {}
5655

56+
5757
def create_poll_fn(bot: TelegramPlugin) -> Function:
5858
return Function(
5959
fn_name="create_poll",
@@ -68,13 +68,15 @@ def create_poll_fn(bot: TelegramPlugin) -> Function:
6868
executable=lambda chat_id, question, options, is_anonymous=False, allows_multiple_answers=False: create_poll_executable(bot, chat_id, question, options, is_anonymous, allows_multiple_answers),
6969
)
7070

71+
7172
def pin_message_executable(tg_plugin: TelegramPlugin, chat_id: str, message_id: int) -> Tuple[FunctionResultStatus, str, dict]:
7273
try:
7374
tg_plugin.pin_message(chat_id=chat_id, message_id=message_id)
7475
return FunctionResultStatus.DONE, "Message pinned successfully", {}
7576
except Exception as e:
7677
return FunctionResultStatus.FAILED, str(e), {}
7778

79+
7880
def pin_message_fn(bot: TelegramPlugin) -> Function:
7981
return Function(
8082
fn_name="pin_message",
@@ -86,13 +88,15 @@ def pin_message_fn(bot: TelegramPlugin) -> Function:
8688
executable=lambda chat_id, message_id: pin_message_executable(bot, chat_id, message_id),
8789
)
8890

91+
8992
def unpin_message_executable(tg_plugin: TelegramPlugin, chat_id: str, message_id: int) -> Tuple[FunctionResultStatus, str, dict]:
9093
try:
9194
tg_plugin.unpin_message(chat_id=chat_id, message_id=message_id)
9295
return FunctionResultStatus.DONE, "Message unpinned successfully", {}
9396
except Exception as e:
9497
return FunctionResultStatus.FAILED, str(e), {}
9598

99+
96100
def unpin_message_fn(bot: TelegramPlugin) -> Function:
97101
return Function(
98102
fn_name="unpin_message",
@@ -104,13 +108,15 @@ def unpin_message_fn(bot: TelegramPlugin) -> Function:
104108
executable=lambda chat_id, message_id: unpin_message_executable(bot, chat_id, message_id),
105109
)
106110

111+
107112
def delete_message_executable(tg_plugin: TelegramPlugin, chat_id: str, message_id: int) -> Tuple[FunctionResultStatus, str, dict]:
108113
try:
109114
tg_plugin.delete_message(chat_id=chat_id, message_id=message_id)
110115
return FunctionResultStatus.DONE, "Message deleted successfully", {}
111116
except Exception as e:
112117
return FunctionResultStatus.FAILED, str(e), {}
113118

119+
114120
def delete_message_fn(bot: TelegramPlugin) -> Function:
115121
return Function(
116122
fn_name="delete_message",

0 commit comments

Comments
 (0)