Skip to content

Commit 89bb77f

Browse files
committed
wip
1 parent d4b2901 commit 89bb77f

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

dcubabot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
logging.basicConfig(
3434
level=logging.INFO,
3535
format='[%(asctime)s] - [%(name)s] - [%(levelname)s] - %(message)s',
36-
filename="bots.log")
36+
)
3737

3838
# Globals ...... yes, globals
3939
logger = logging.getLogger("DCUBABOT")

handlers/update_groups.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
11
#!/usr/bin/python3
22
# -*- coding: utf-8 -*-
3+
import logging
34
from time import sleep
45

56
from tg_ids import DC_GROUP_CHATID
67

78
from pony.orm import db_session, select
89
from telegram import Update
9-
from telegram.ext import Updater, CallbackContext
10+
from telegram.ext import CallbackContext
1011

1112
from models import Listable
1213

14+
logger = logging.getLogger(__name__)
15+
1316

1417
def update_group_url(context: CallbackContext, chat_id: str) -> (str, str, bool):
1518
try:
1619
url = context.bot.export_chat_invite_link(chat_id=chat_id)
1720
return chat_id, url, True # too GO-like huh?
18-
except: # TODO: filter excepts
21+
except Exception:
22+
logger.error(f"Could not create invite link for {chat_id}", exc_info=True)
1923
return None, None, False # too GO-like huh?
2024

2125

2226
def update_groups(context: CallbackContext):
27+
logger.info("Starting update_groups job")
2328
with db_session:
2429
chats = list(select((l.id, l.chat_id, l.name) for l in Listable if l.validated))
25-
for id, (chat_id, url, validated), name in [(id,update_group_url(context, chat_id), name) for id, chat_id, name in
30+
logger.info(f"Found {len(chats)} groups to update")
31+
32+
for id, (chat_id, url, validated), name in [(id, update_group_url(context, chat_id), name) for id, chat_id, name in
2633
chats]:
2734
sleep(1)
2835
if not validated:
36+
logger.warning(f"Failed to update URL for group '{name}'. De-validating.")
2937
with db_session:
3038
Listable[id].validated = False
3139
context.bot.send_message(chat_id=DC_GROUP_CHATID, text=f"El grupo {name} murió 💀")
3240
else:
41+
logger.info(f"Updating URL for group '{name}'")
3342
with db_session:
3443
Listable[id].url = url
44+
logger.info("Finished update_groups job")
3545

3646

3747
def actualizar_grupos(update: Update, context: CallbackContext):
48+
logger.info(f"Manual update of groups triggered by {update.effective_user.id}")
49+
update.message.reply_text("Actualizando grupos...")
3850
update_groups(context)
51+
update.message.reply_text("¡Grupos actualizados!")

main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def main():
2626
logging.basicConfig(
2727
level=logging.INFO,
2828
format='[%(asctime)s] - [%(name)s] - [%(levelname)s] - %(message)s',
29-
filename="bots.log"
3029
)
3130

3231
init_db()

0 commit comments

Comments
 (0)