-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ravachol-yang/welcome
add member welcome and templates config
- Loading branch information
Showing
9 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
# info.py | ||
# info_handler.py | ||
|
||
from telebot import TeleBot | ||
from telebot.types import Message | ||
|
||
from app.services.info_service import generate_info | ||
|
||
def get_info(message: Message, bot: TeleBot): | ||
bot.send_message(message.chat.id, "Hello, I'm a bot of Randomology ~") | ||
name = message.from_user.first_name | ||
id = message.from_user.id | ||
info = generate_info(name, id) | ||
bot.send_message(message.chat.id, info, parse_mode="MarkdownV2") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# member_hander.py | ||
|
||
from telebot import TeleBot | ||
from telebot.types import Message | ||
|
||
from app.services.member_service import generate_welcome | ||
|
||
# invoke when new member joins | ||
def get_welcome(message:Message, bot:TeleBot): | ||
# typing ... | ||
bot.send_chat_action(message.chat.id, "typing") | ||
new_member = message.new_chat_members | ||
welcome = generate_welcome(new_member[0].first_name, new_member[0].id) | ||
bot.send_message(message.chat.id, welcome, parse_mode="MarkdownV2") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# random_text.py | ||
# text_handler.py | ||
from telebot import TeleBot | ||
from telebot.types import Message | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# info_service.py | ||
|
||
from configs import templates | ||
|
||
# generate info | ||
def generate_info(name, id): | ||
return templates.INFO_MESSAGE.format(name=name, id=id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# member_service.py | ||
|
||
from configs import templates | ||
|
||
# generate welcome message | ||
def generate_welcome(name, id): | ||
return templates.WELCOME_MESSAGE.format(name=name, id=id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# templates | ||
|
||
# welcome message, will be parsed as markdown | ||
WELCOME_MESSAGE=""" | ||
[{name}](tg://user?id={id}), 我们信任您加入本群时已经从系统管理员那里了解了日常注意事项,总结起来无外乎以下三点: | ||
\#1\) ""?'\*\!\*:\!\$\?\*:\*?\*?:😈😈 | ||
\#2\) Rhrhd dhod dbdog | ||
\#3\) цзц Иатщв, Лоботомия\!\!\! | ||
""" | ||
INFO_MESSAGE=""" | ||
您好,[{name}](tg://user?id={id}),我是[Randomology Bot](https://github.com/ravachol-yang/randomology) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# info_test.py | ||
|
||
from app.services.info_service import generate_info | ||
from configs import templates | ||
|
||
def test_welcome_template(): | ||
assert isinstance(templates.INFO_MESSAGE, str) | ||
|
||
def test_info_generated(): | ||
info = generate_info("test", 111) | ||
assert isinstance(info, str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# member tests | ||
|
||
from app.services.member_service import generate_welcome | ||
from configs import templates | ||
|
||
def test_welcome_template(): | ||
assert isinstance(templates.WELCOME_MESSAGE, str) | ||
|
||
def test_welcome_generated(): | ||
welcome = generate_welcome("test",111) | ||
assert isinstance(welcome, str) |