limit users for channel helper

This commit is contained in:
bakatrouble 2020-05-05 11:47:40 +03:00
parent 89e839d36f
commit 203efae85d
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,26 @@
# Generated by Django 3.0rc1 on 2020-05-05 08:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bots', '0021_auto_20200212_2022'),
]
operations = [
migrations.CreateModel(
name='ChannelHelperUser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=32)),
('user_id', models.BigIntegerField(db_index=True)),
],
),
migrations.AddField(
model_name='channelhelperbotmoduleconfig',
name='users',
field=models.ManyToManyField(to='bots.ChannelHelperUser'),
),
]

View File

@ -16,9 +16,18 @@ from djconfig import config
from bots.models import TelegramBotModuleConfig
class ChannelHelperUser(models.Model):
name = models.CharField(max_length=32)
user_id = models.BigIntegerField(db_index=True)
def __str__(self):
return self.name
class ChannelHelperBotModuleConfig(TelegramBotModuleConfig):
chat_id = models.CharField(max_length=32)
queued = models.BooleanField(default=False)
users = models.ManyToManyField(ChannelHelperUser)
MODULE_NAME = 'Channel helper'
@ -64,6 +73,10 @@ class ChannelHelperBotModuleConfig(TelegramBotModuleConfig):
i.delete()
def handle_message(self, update: Update, ctx: CallbackContext):
if self.users.count() and not self.users.filter(user_id=update.effective_user.id).count():
update.effective_message.reply_text('GTFO')
return
m = update.effective_message
bot = ctx.bot
i = QueuedItem(config=self)