mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-04-29 16:57:09 +08:00
doc: add info
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
988ccc7265
commit
1f62958d3a
15
README.md
15
README.md
@ -1,7 +1,7 @@
|
|||||||
# tg_bot_collections
|
# tg_bot_collections
|
||||||
Collections of yihong0618's telegram bot
|
Collections of yihong0618's telegram bot
|
||||||
|
|
||||||
for my channel: https://t.me/hyi0618
|
for yihong0618's channel: https://t.me/hyi0618
|
||||||
|
|
||||||
|
|
||||||
## Bot -> poster
|
## Bot -> poster
|
||||||
@ -17,5 +17,16 @@ for my channel: https://t.me/hyi0618
|
|||||||
|
|
||||||
1. pip install -r requirements.txt
|
1. pip install -r requirements.txt
|
||||||
2. Get tg token, ask Google or ChatGPT, need get it from [BotFather](https://t.me/BotFather)
|
2. Get tg token, ask Google or ChatGPT, need get it from [BotFather](https://t.me/BotFather)
|
||||||
3. python hy_tg.py ${tg_token}
|
3. python tg.py ${tg_token}
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
- Any issue reports or PRs are welcome.
|
||||||
|
- Any other bot type like slack/discord welcome
|
||||||
|
- Before PR, use `pip install -U black` then `black .` first
|
||||||
|
|
||||||
|
## Appreciation
|
||||||
|
|
||||||
|
- Thank you, that's enough. Just enjoy it.
|
||||||
|
|
||||||
|
@ -145,7 +145,6 @@ def main():
|
|||||||
styles_list = list(STYLES.keys())
|
styles_list = list(STYLES.keys())
|
||||||
style = random.choice(styles_list)
|
style = random.choice(styles_list)
|
||||||
try:
|
try:
|
||||||
# TODO why this memory leak?
|
|
||||||
with SpooledTemporaryFile(max_size=MAX_IN_MEMORY) as out_image:
|
with SpooledTemporaryFile(max_size=MAX_IN_MEMORY) as out_image:
|
||||||
draw_pretty_map(location, style, out_image)
|
draw_pretty_map(location, style, out_image)
|
||||||
# tg can only send image less than 10MB
|
# tg can only send image less than 10MB
|
||||||
@ -160,7 +159,35 @@ def main():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
bot.reply_to(message, "Something wrong please check")
|
bot.reply_to(message, "Something wrong please check")
|
||||||
bot.delete_message(reply_message.chat.id, reply_message.message_id)
|
bot.delete_message(reply_message.chat.id, reply_message.message_id)
|
||||||
# we need this, fuck it
|
gc.collect()
|
||||||
|
|
||||||
|
@bot.message_handler(content_types=["location", "venue"])
|
||||||
|
def map_location_handler(message: Message):
|
||||||
|
# TODO refactor the function
|
||||||
|
reply_message = bot.reply_to(
|
||||||
|
message,
|
||||||
|
"Generating pretty map using location now, may take some time please wait:",
|
||||||
|
)
|
||||||
|
location = "{0}, {1}".format(
|
||||||
|
message.location.latitude, message.location.longitude
|
||||||
|
)
|
||||||
|
styles_list = list(STYLES.keys())
|
||||||
|
style = random.choice(styles_list)
|
||||||
|
try:
|
||||||
|
with SpooledTemporaryFile(max_size=MAX_IN_MEMORY) as out_image:
|
||||||
|
draw_pretty_map(location, style, out_image)
|
||||||
|
# tg can only send image less than 10MB
|
||||||
|
with open("map_out.jpg", "wb") as f: # for debug
|
||||||
|
shutil.copyfileobj(out_image, f)
|
||||||
|
out_image.seek(0)
|
||||||
|
bot.send_photo(
|
||||||
|
message.chat.id, out_image, reply_to_message_id=message.message_id
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc()
|
||||||
|
bot.reply_to(message, "Something wrong please check")
|
||||||
|
bot.delete_message(reply_message.chat.id, reply_message.message_id)
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
# Start bot
|
# Start bot
|
Loading…
x
Reference in New Issue
Block a user