refactor stan
This commit is contained in:
+3
-16
@@ -1,12 +1,10 @@
|
|||||||
import shelve
|
import shelve
|
||||||
from flask import request, abort
|
from flask import request, abort
|
||||||
import threading
|
|
||||||
|
|
||||||
from . import stan
|
from . import stan
|
||||||
from . import report
|
|
||||||
from . import rules
|
from . import rules
|
||||||
|
|
||||||
from .helpers import represent_as_get, detect_args
|
from .helpers import represent_as_get, detect_args, update_stats
|
||||||
from .filters import *
|
from .filters import *
|
||||||
from .config import *
|
from .config import *
|
||||||
|
|
||||||
@@ -227,19 +225,8 @@ def default_query(inline_query):
|
|||||||
chat_types=['supergroup', 'group'])
|
chat_types=['supergroup', 'group'])
|
||||||
def handle_msg(message: types.Message):
|
def handle_msg(message: types.Message):
|
||||||
""" Count messages, Stan. """
|
""" Count messages, Stan. """
|
||||||
with shelve.open(f'{DATA}{message.chat.id}', writeback=True) as s:
|
update_stats(message)
|
||||||
if 'Messages' not in s:
|
stan.act(message)
|
||||||
report.reset_report_stats(message.chat.id)
|
|
||||||
|
|
||||||
if message.from_user.id not in s['Messages']:
|
|
||||||
s['Messages'][message.from_user.id] = {'User': message.from_user, 'Count': 1}
|
|
||||||
logging.warning(f'CNTR {message.chat.id}: {message.from_user.first_name} ({message.from_user.id})')
|
|
||||||
else:
|
|
||||||
s['Messages'][message.from_user.id]['Count'] += 1
|
|
||||||
|
|
||||||
quote = stan.speak(50)
|
|
||||||
if quote:
|
|
||||||
threading.Thread(target=stan.send_quote, args=(len(quote) * 0.13, message, quote)).start()
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
""" Send User's info. """
|
""" Send User's info. """
|
||||||
|
import shelve
|
||||||
|
import logging
|
||||||
|
from . import report
|
||||||
|
from .config import DATA
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
from telebot import types
|
from telebot import types
|
||||||
|
|
||||||
@@ -16,3 +20,15 @@ def detect_args(message: types.Message):
|
|||||||
else:
|
else:
|
||||||
if len(message.text.split()) > 1:
|
if len(message.text.split()) > 1:
|
||||||
return ' '.join(message.text.split()[1:])
|
return ' '.join(message.text.split()[1:])
|
||||||
|
|
||||||
|
|
||||||
|
def update_stats(message: types.Message):
|
||||||
|
with shelve.open(f'{DATA}{message.chat.id}', writeback=True) as s:
|
||||||
|
if 'Messages' not in s:
|
||||||
|
report.reset_report_stats(message.chat.id)
|
||||||
|
|
||||||
|
if message.from_user.id not in s['Messages']:
|
||||||
|
s['Messages'][message.from_user.id] = {'User': message.from_user, 'Count': 1}
|
||||||
|
logging.warning(f'CNTR {message.chat.id}: {message.from_user.first_name} ({message.from_user.id})')
|
||||||
|
else:
|
||||||
|
s['Messages'][message.from_user.id]['Count'] += 1
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
""" Stan's commands and reactions. """
|
""" Stan's commands and reactions. """
|
||||||
import random
|
import random
|
||||||
|
import threading
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from .config import bot, types
|
from .config import bot, types
|
||||||
from .filters import is_white, is_nongrata
|
from .filters import is_white, is_nongrata
|
||||||
@@ -20,6 +21,12 @@ def send_quote(after_sec, message, quote):
|
|||||||
bot.send_message(message.chat.id, quote)
|
bot.send_message(message.chat.id, quote)
|
||||||
|
|
||||||
|
|
||||||
|
def act(message):
|
||||||
|
quote = speak(50)
|
||||||
|
if quote:
|
||||||
|
threading.Thread(target=send_quote, args=(len(quote) * 0.13, message, quote)).start()
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(func=is_white, commands=['add'])
|
@bot.message_handler(func=is_white, commands=['add'])
|
||||||
def add_stan_quote(message):
|
def add_stan_quote(message):
|
||||||
if message.reply_to_message and message.reply_to_message.text:
|
if message.reply_to_message and message.reply_to_message.text:
|
||||||
|
|||||||
Reference in New Issue
Block a user