Telegram allowlist
Tweak skip day queries
This commit is contained in:
parent
ccd523d740
commit
e90df3d61e
4 changed files with 11 additions and 16 deletions
|
|
@ -116,17 +116,17 @@ def skip_day_put(user, date):
|
|||
return SkipDay.create(user=user, date=date)
|
||||
|
||||
def skip_day_delete(user, date):
|
||||
q = SkipDay.delete().where(SkipDay.user == user & SkipDay.date == date)
|
||||
q = SkipDay.delete().where((SkipDay.user == user) & (SkipDay.date == date))
|
||||
return q.execute()
|
||||
|
||||
def skip_days_upcoming(user):
|
||||
return (SkipDay.select()
|
||||
.where(SkipDay.user == user and SkipDay.date >= datetime.date.today())
|
||||
.where((SkipDay.user == user) & (SkipDay.date >= datetime.date.today()))
|
||||
.order_by(SkipDay.date)
|
||||
.limit(10))
|
||||
|
||||
def skip_day_contains(user, date):
|
||||
q = SkipDay.select().where(SkipDay.user == user & SkipDay.date == date)
|
||||
q = SkipDay.select().where((SkipDay.user == user) & (SkipDay.date == date))
|
||||
return len(q) > 0
|
||||
|
||||
def order_status_put(orders_pool, user, mastodon_id, created_at, due_at, text, punishment_for=None):
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ MASTODON_OAUTH_CLIENT_NAME = os.environ.get('MASTODON_OAUTH_CLIENT_NAME', 'Gear
|
|||
MASTODON_OAUTH_CLIENT_WEBSITE = os.environ.get('MASTODON_OAUTH_CLIENT_WEBSITE')
|
||||
|
||||
TELEGRAM_API_TOKEN = os.environ.get('TELEGRAM_API_TOKEN')
|
||||
TELEGRAM_CHAT_ID = int(os.environ.get('TELEGRAM_CHAT_ID'))
|
||||
TELEGRAM_ALLOWLIST = os.environ.get('TELEGRAM_ALLOWLIST', '').split(',')
|
||||
TELEGRAM_COMMAND_TIMEOUT = int(os.environ.get('TELEGRAM_COMMAND_TIMEOUT', 120))
|
||||
TELEGRAM_BOT_NAME = os.environ.get('TELEGRAM_BOT_NAME')
|
||||
TELEGRAM_BOT_DOMAIN = os.environ.get('TELEGRAM_BOT_DOMAIN')
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class StartCommand(TelegramCommand):
|
|||
|
||||
user_add(username, chat_id)
|
||||
|
||||
yield "Welcome to gear orders bot. Add a dom with `/dom_add <username>` or ask a sub to add you."
|
||||
yield "Welcome to Gear Orders bot.\n\nEdit your orders at {FLASK_URL}\n\nAdd a dom with `/dom_add <username>` or ask a sub to add you."
|
||||
|
||||
class DomAddCommand(TelegramCommand):
|
||||
command_regex = re.compile(r"^\/dom_add( (?P<username>@?\w+))$")
|
||||
|
|
@ -45,7 +45,7 @@ class DomAddCommand(TelegramCommand):
|
|||
yield f"Successfully added {dom_username} to your list of doms"
|
||||
|
||||
t = Telegram(session)
|
||||
await t.message_send(dom.telegram_chat_id, f"@{sub_username} has added you as a dom. You may administer their orders at {FLASK_URL}")
|
||||
await t.message_send(dom.telegram_chat_id, f"@{sub_username} has added you as a dom. You may edit their orders at {FLASK_URL}")
|
||||
|
||||
class DomRemoveCommand(TelegramCommand):
|
||||
command_regex = re.compile(r"^\/dom_remove( (?P<username>@?\w+))$")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
import asyncio
|
||||
|
||||
from settings import ENV, TELEGRAM_API_TOKEN, TELEGRAM_CHAT_ID, TELEGRAM_COMMAND_TIMEOUT
|
||||
from settings import ENV, TELEGRAM_API_TOKEN, TELEGRAM_ALLOWLIST, TELEGRAM_COMMAND_TIMEOUT
|
||||
from util import make_session
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -40,15 +40,9 @@ class Telegram:
|
|||
return await response.json()
|
||||
|
||||
async def message_send(self, chat_id, text):
|
||||
chat_id_actual = chat_id
|
||||
text_actual = text
|
||||
if ENV == 'dev' and chat_id != TELEGRAM_CHAT_ID:
|
||||
text_actual = f"⚠️ Message intended for chat id {chat_id}\n\n" + text
|
||||
chat_id_actual = TELEGRAM_CHAT_ID
|
||||
|
||||
data = {
|
||||
'chat_id': chat_id_actual,
|
||||
'text': text_actual
|
||||
'chat_id': chat_id,
|
||||
'text': text
|
||||
}
|
||||
|
||||
return await self.post('sendMessage', data=data)
|
||||
|
|
@ -102,7 +96,8 @@ async def handle_commands(commands=[], loop=None):
|
|||
if('message' in update):
|
||||
chat_id = update['message']['chat']['id']
|
||||
|
||||
if(chat_id != TELEGRAM_CHAT_ID):
|
||||
if(update['message']['chat']['type'] != "private" or
|
||||
update['message']['chat']['username'] not in TELEGRAM_ALLOWLIST):
|
||||
continue
|
||||
|
||||
if('text' not in update['message']):
|
||||
|
|
|
|||
Loading…
Reference in a new issue