add spoiler bot
This commit is contained in:
parent
5048f3e81d
commit
9fa029d896
@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 3.0rc1 on 2020-12-11 10:36
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bots', '0023_overlaybotmoduleconfig_send_avatar_on_start'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SpoilerBotModuleConfig',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SpoilerMessage',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('text', models.TextField()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -3,6 +3,7 @@ from .channel_helper import ChannelHelperBotModuleConfig, QueuedItem, ChannelHel
|
|||||||
from .echo import EchoBotModuleConfig
|
from .echo import EchoBotModuleConfig
|
||||||
from .cyberlina import CyberLinaBotModuleConfig
|
from .cyberlina import CyberLinaBotModuleConfig
|
||||||
from .ping import PingBotModuleConfig
|
from .ping import PingBotModuleConfig
|
||||||
|
from .spoiler import SpoilerBotModuleConfig
|
||||||
|
|
||||||
BOT_MODULES = [EchoBotModuleConfig, ChannelHelperBotModuleConfig, OverlayBotModuleConfig, CyberLinaBotModuleConfig,
|
BOT_MODULES = [EchoBotModuleConfig, ChannelHelperBotModuleConfig, OverlayBotModuleConfig, CyberLinaBotModuleConfig,
|
||||||
PingBotModuleConfig]
|
PingBotModuleConfig, SpoilerBotModuleConfig]
|
||||||
|
36
bots/modules/spoiler.py
Normal file
36
bots/modules/spoiler.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from django.db import models
|
||||||
|
from telegram import Update, InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardMarkup, \
|
||||||
|
InlineKeyboardButton
|
||||||
|
from telegram.ext import Dispatcher, CallbackContext, InlineQueryHandler, CallbackQueryHandler
|
||||||
|
|
||||||
|
from bots.models import TelegramBotModuleConfig
|
||||||
|
|
||||||
|
|
||||||
|
class SpoilerMessage(models.Model):
|
||||||
|
text = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
|
class SpoilerBotModuleConfig(TelegramBotModuleConfig):
|
||||||
|
MODULE_NAME = 'Spoiler'
|
||||||
|
|
||||||
|
def inline_handler(self, update: Update, ctx: CallbackContext):
|
||||||
|
sm = SpoilerMessage.objects.create(text=update.inline_query.query)
|
||||||
|
update.inline_query.answer(results=[InlineQueryResultArticle(
|
||||||
|
id=str(sm.pk),
|
||||||
|
title='Send spoiler',
|
||||||
|
input_message_content=InputTextMessageContent('This is a spoiler'),
|
||||||
|
reply_markup=InlineKeyboardMarkup([InlineKeyboardButton('Read content', callback_data='read {}'.format(sm.pk))])
|
||||||
|
)])
|
||||||
|
|
||||||
|
def read_handler(self, update: Update, ctx: CallbackContext):
|
||||||
|
_, smid = update.callback_query.data.split()
|
||||||
|
try:
|
||||||
|
sm = SpoilerMessage.objects.get(pk=smid)
|
||||||
|
except SpoilerMessage.DoesNotExist:
|
||||||
|
return update.callback_query.answer('Message does not exist')
|
||||||
|
update.callback_query.answer(sm.text, alert=True)
|
||||||
|
|
||||||
|
def build_dispatcher(self, dispatcher: Dispatcher):
|
||||||
|
dispatcher.add_handler(InlineQueryHandler(self.inline_handler))
|
||||||
|
dispatcher.add_handler(CallbackQueryHandler(self.read_handler, pattern=r'^read \d+$'))
|
||||||
|
return dispatcher
|
@ -1,4 +1,5 @@
|
|||||||
amqp==2.3.2
|
amqp==2.3.2
|
||||||
|
APScheduler==3.6.3
|
||||||
asgiref==3.2.3
|
asgiref==3.2.3
|
||||||
asn1crypto==0.24.0
|
asn1crypto==0.24.0
|
||||||
async-generator==1.10
|
async-generator==1.10
|
||||||
@ -16,6 +17,7 @@ chardet==3.0.4
|
|||||||
constantly==15.1.0
|
constantly==15.1.0
|
||||||
cryptography==2.8
|
cryptography==2.8
|
||||||
daphne==2.4.0
|
daphne==2.4.0
|
||||||
|
decorator==4.4.2
|
||||||
Django==3.0rc1
|
Django==3.0rc1
|
||||||
django-bootstrap4==1.0.1
|
django-bootstrap4==1.0.1
|
||||||
django-crispy-forms==1.8.1
|
django-crispy-forms==1.8.1
|
||||||
@ -49,7 +51,6 @@ oauthlib==3.0.1
|
|||||||
packaging==19.2
|
packaging==19.2
|
||||||
Pillow==5.4.1
|
Pillow==5.4.1
|
||||||
priority==1.3.0
|
priority==1.3.0
|
||||||
psycopg2-binary==2.7.6.1
|
|
||||||
pyaes==1.6.1
|
pyaes==1.6.1
|
||||||
pyasn1==0.4.8
|
pyasn1==0.4.8
|
||||||
pyasn1-modules==0.2.7
|
pyasn1-modules==0.2.7
|
||||||
@ -63,8 +64,8 @@ PySocks==1.6.8
|
|||||||
pyTelegramBotAPI==3.6.6
|
pyTelegramBotAPI==3.6.6
|
||||||
python-anticaptcha==0.3.1
|
python-anticaptcha==0.3.1
|
||||||
python-crontab==2.3.6
|
python-crontab==2.3.6
|
||||||
python-dateutil==2.7.5
|
python-dateutil==2.8.1
|
||||||
python-telegram-bot==12.2.0
|
python-telegram-bot==13.1
|
||||||
python-twitter==3.5
|
python-twitter==3.5
|
||||||
pytz==2018.9
|
pytz==2018.9
|
||||||
PyYAML==3.13
|
PyYAML==3.13
|
||||||
@ -80,6 +81,7 @@ TgCrypto==1.1.1
|
|||||||
tornado==6.0.3
|
tornado==6.0.3
|
||||||
Twisted==19.10.0
|
Twisted==19.10.0
|
||||||
txaio==18.8.1
|
txaio==18.8.1
|
||||||
|
tzlocal==2.1
|
||||||
Unidecode==1.1.1
|
Unidecode==1.1.1
|
||||||
urllib3==1.24.1
|
urllib3==1.24.1
|
||||||
vine==1.2.0
|
vine==1.2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user