announce on telegram
This commit is contained in:
parent
06f10fd479
commit
a569dde23b
11 changed files with 62 additions and 7 deletions
|
@ -30,13 +30,22 @@ def announce_items():
|
|||
f.write(r.content)
|
||||
f.close()
|
||||
image = f.name
|
||||
if getattr(settings, "SIGNAL_ANNOUNCE_GROUP"):
|
||||
r = rpc.send(
|
||||
message, group=settings.SIGNAL_ANNOUNCE_GROUP,
|
||||
message,
|
||||
group=settings.SIGNAL_ANNOUNCE_GROUP,
|
||||
preview_url=link,
|
||||
preview_title=item.title,
|
||||
preview_image=image,
|
||||
preview_description=description,
|
||||
)
|
||||
if getattr(settings, "TELEGRAM_ANNOUNCE_CHANNEL"):
|
||||
message = f'<a href="{link}">{item.title}</a>'
|
||||
r = telegram_rpc.send(
|
||||
message,
|
||||
channel=settings.TELEGRAM_ANNOUNCE_CHANNEL,
|
||||
preview_image=image,
|
||||
)
|
||||
item.save()
|
||||
if image:
|
||||
os.unlink(f.name)
|
||||
|
|
|
@ -60,6 +60,7 @@ INSTALLED_APPS = [
|
|||
"app.user",
|
||||
"app.item",
|
||||
"app.signalbot",
|
||||
"app.telegrambot",
|
||||
"app.page",
|
||||
]
|
||||
|
||||
|
|
0
app/telegrambot/__init__.py
Normal file
0
app/telegrambot/__init__.py
Normal file
3
app/telegrambot/admin.py
Normal file
3
app/telegrambot/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
app/telegrambot/apps.py
Normal file
6
app/telegrambot/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TelegrambotConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "app.telegrambot"
|
0
app/telegrambot/migrations/__init__.py
Normal file
0
app/telegrambot/migrations/__init__.py
Normal file
3
app/telegrambot/models.py
Normal file
3
app/telegrambot/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
26
app/telegrambot/rpc.py
Normal file
26
app/telegrambot/rpc.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import asyncio
|
||||
|
||||
import telegram
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def send(msg, to=None, channel=None, preview_url=None, preview_title=None, preview_description=None, preview_image=None):
|
||||
bot = telegram.Bot(token=settings.TELEGRAM_TOKEN)
|
||||
if preview_image:
|
||||
asyncio.run(bot.send_photo(
|
||||
chat_id=channel,
|
||||
caption=msg,
|
||||
photo=preview_image,
|
||||
parse_mode='html'
|
||||
))
|
||||
else:
|
||||
asyncio.run(bot.send_message(
|
||||
chat_id=channel,
|
||||
text=msg,
|
||||
parse_mode='html'
|
||||
))
|
||||
|
||||
|
||||
def send_reaction(target_address, target_ts, emoji, to=None, group=None, remove=False):
|
||||
pass
|
3
app/telegrambot/tests.py
Normal file
3
app/telegrambot/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
app/telegrambot/views.py
Normal file
3
app/telegrambot/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
|
@ -13,3 +13,4 @@ django-celery-results
|
|||
django-celery-beat
|
||||
redis
|
||||
django-brake
|
||||
python-telegram-bot
|
||||
|
|
Loading…
Reference in a new issue