Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
Consolidando personalidades novas
Browse files Browse the repository at this point in the history
  • Loading branch information
iuriguilherme committed Sep 15, 2020
1 parent e3374e4 commit 9a1b623
Show file tree
Hide file tree
Showing 26 changed files with 978 additions and 291 deletions.
13 changes: 10 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@

import subprocess, sys

from matebot.tp_matebot import bot as telepot_bot
from matebot.aio_matebot import run as aiogram_bot

from matebot.ptb_matebot import app
flask_bot = app
try:
from matebot.ptb_matebot import app
flask_bot = app
except Exception as e:
logging.debug(repr(e))

try:
from matebot.tp_matebot import bot as telepot_bot
except Exception as e:
logging.debug(repr(e))

if __name__ == "__main__":
mode = 'aiogram'
Expand Down
49 changes: 25 additions & 24 deletions doc/default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Config(BaseSettings):
'info': {
'website': "https://matehackers.org",
'repository': "https://github.com/matehackers/matebot",
'group': "@matehackerspoa",
'channel': "@matehackers",
'group': "https://t.me/joinchat/CwFUFkf-dKW34FPBjEJs9Q",
'channel': "@matebotnews",
'admin': "@desobedientecivil",
'dev': "@desobedientecivil",
## Plugin donate - doações
Expand Down Expand Up @@ -72,18 +72,22 @@ class Config(BaseSettings):
'plugins': {
## Lista de plugins disponíveis somente para bot.users['alpha']
## Sugestão de uso: pessoa que criou o bot, etc.
'alpha': ["admin","log","ytdl","start",],
'alpha': ["admin",],
## Lista de plugins disponíveis somente para bot.users['beta']
## Sugestão de uso: administradora(e)s, moderadora(e)s, etc.
'beta': ["admin","log","totalvoice","ytdl",],
'beta': ["admin",],
## Lista de plugins disponíveis somente para bot.users['gamma']
'gamma': ["ytdl",],
## Sugestão de uso: grupos e canais onde quem administra tem controle
'gamma': ["donate",],
## Lista de plugins disponíveis somente para bot.users['delta']
'delta': ["hashes","mate-matica",],
## Sugestão de uso: grupos e canais onde quem administra acompanha mas não
## controla
'delta': ["personalidades", "feedback", "welcome",],
## Lista de plugins disponíveis somente para bot.users['epsilon']
'epsilon': ["archive","hashes","mate-matica","qr",],
## Sugestão de uso: grupos, canais e usuários que usam o bot regularmente
'epsilon': ["archive", "hashes", "mate_matica", "qr", "ytdl",],
## Lista de plugins ativos para todo mundo
'omega': ["telegram","donate",],
'omega': ["telegram",],
}, # plugins

'users': {
Expand All @@ -95,32 +99,29 @@ class Config(BaseSettings):
'delta': [-1001233916997,],
'epsilon': [777000,-1001207858341,],
## Plugin Welcome
'pegadinha': [],
'pegadinha': [-1001233916997,],
## Plugin Tropixel
'tropixel': [],
'tropixel': [-1001233916997,],
### Não tem 'omega' porque 'omega' é qualquer outro id
### Usuários e grupos especiais (que são referenciados pelo nome da chave)
'special': {
## Grupo para testar bots
## https://t.me/joinchat/CwFUFhbgApLHBMLoNnkiRg
'test': -1001233916997,
## Conta de serviço do telegram
'service': 777000,
## Grupo público para desenvolvedora(e)s e usuária(o)s
## https://t.me/joinchat/CwFUFkf-dKW34FPBjEJs9Q
'pub': -1001207858341,
## Conta de serviço do telegram
'service': 777000,
## Grupo para onde são logados os erros / exceções
## https://t.me/joinchat/CwFUFhy2NQRi_9Cc60v_aA
'debug': -481703172,
## Grupo para onde vão mensagens de informação
## https://t.me/joinchat/CwFUFhy2NQRi_9Cc60v_aA
'info': -481703172,
## Grupo para onde são logados os erros / exceções
## https://t.me/joinchat/CwFUFhy2NQRi_9Cc60v_aA
'debug': -481703172,
## Grupo para onde vão as mensagens do comando /feedback
## https://t.me/joinchat/CwFUFhy2NQRi_9Cc60v_aA
'feedback': -481703172,
## Grupo para onde vão as mensagens do plugin log
## https://t.me/joinchat/CwFUFhy2NQRi_9Cc60v_aA
'log': -481703172,
## Grupo para testar bots
## https://t.me/joinchat/CwFUFhbgApLHBMLoNnkiRg
'test': -1001233916997,
},
}, # users

Expand Down Expand Up @@ -152,14 +153,14 @@ class Config(BaseSettings):
}, # testing
'development': {
'token': "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
'info': default_bot['info'],
## Exemplo para mudar só a personalidade
'info': dict(default_bot['info'].copy, personalidade = 'metarec'),
'plugins': default_bot['plugins'],
## Exemplo (ruim) para herdar configurações padrão alterando algumas
'users': dict(default_bot['users'].copy(), special = {
'log': -481703172,
'debug': -481703172,
'feedback': -481703172,
'info': -481703172,
}),
}),
}, # development
} # bots
2 changes: 1 addition & 1 deletion matebot/aio_matebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
)

async def on_startup(dispatcher: Dispatcher):
await controllers.add_handlers(dispatcher)
await controllers.on_startup(dispatcher)
logging.info(u"Deu Certo, nosso id é {}".format(str(dispatcher.bot.id)))
try:
await dispatcher.bot.send_message(
Expand Down
74 changes: 48 additions & 26 deletions matebot/aio_matebot/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,68 @@
any_error_callback,
)

## Filters
from matebot.aio_matebot.controllers.filters import (
IsReplyToIdFilter,
)

## Plugins
from matebot.plugins import (
default as plugin_default,
admin as plugin_admin,
archive as plugin_archive,
donate as plugin_donate,
feedback as plugin_feedback,
hashes as plugin_hashes,
mate_matica as plugin_matematica,
personalidades as plugin_personalidades,
qr as plugin_qr,
tropixel as plugin_tropixel,
welcome as plugin_welcome,
ytdl as plugin_ytdl,
)

async def add_filters(dispatcher: Dispatcher):
### Filters
dispatcher.filters_factory.bind(IsReplyToIdFilter)

async def add_handlers(dispatcher: Dispatcher):
from matebot.plugins import (
telegram as plugin_telegram,
admin as plugin_admin,
feedback as plugin_feedback,
archive as plugin_archive,
qr as plugin_qr,
donate as plugin_donate,
hashes as plugin_hashes,
mate_matica as plugin_matematica,
tropixel as plugin_tropixel,
ytdl as plugin_ytdl,
welcome as plugin_welcome,
personalidades as plugin_personalidades,
)
plugin_telegram.add_handlers(dispatcher)
plugin_admin.add_handlers(dispatcher)
plugin_feedback.add_handlers(dispatcher)
## Plugins de personalidades
await plugin_personalidades.add_handlers(dispatcher)
## Plugins gerais
plugin_archive.add_handlers(dispatcher)
plugin_qr.add_handlers(dispatcher)
plugin_donate.add_handlers(dispatcher)
plugin_hashes.add_handlers(dispatcher)
plugin_matematica.add_handlers(dispatcher)
plugin_qr.add_handlers(dispatcher)
plugin_ytdl.add_handlers(dispatcher)
await plugin_personalidades.add_handlers(dispatcher)
try:
plugin_tropixel.add_handlers(dispatcher)
except KeyError:
logging.warning(u"plugin tropixel não configurado")
## Plugins especiais
if dispatcher.bot.info.get('personalidade') in ['default', 'metarec', 'pave']:
plugin_donate.add_handlers(dispatcher)
plugin_feedback.add_handlers(dispatcher)
plugin_admin.add_handlers(dispatcher)
## Plugins mais que especiais
if dispatcher.bot.info.get('personalidade') in ['default', 'metarec']:
try:
plugin_tropixel.add_handlers(dispatcher)
except KeyError:
logging.warning(u"plugin tropixel não configurado")
try:
plugin_welcome.add_handlers(dispatcher)
except KeyError:
logging.warning(u"plugin welcome não configurado")

plugin_default.add_handlers(dispatcher)
## Todas updates que não forem tratadas por handlers anteriores
dispatcher.register_message_handler(
any_message_callback,
content_types = types.message.ContentType.ANY,
)
dispatcher.register_edited_message_handler(any_edited_message_callback)
dispatcher.register_channel_post_handler(any_channel_post_callback)
dispatcher.register_edited_channel_post_handler(any_edited_channel_post_callback)
dispatcher.register_edited_channel_post_handler(
any_edited_channel_post_callback,
)
dispatcher.register_errors_handler(any_error_callback)

async def on_startup(dispatcher: Dispatcher):
await add_filters(dispatcher)
await add_handlers(dispatcher)
36 changes: 24 additions & 12 deletions matebot/aio_matebot/controllers/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
# MA 02110-1301, USA.
#

import json

from aiogram import (
Dispatcher,
exceptions,
Expand All @@ -34,8 +32,9 @@
)

from matebot.plugins.log import (
info_logger,
debug_logger,
exception_logger,
info_logger,
)

async def send_message(
Expand Down Expand Up @@ -104,27 +103,37 @@ async def send_message(

async def message_callback(
message: types.Message,
description: str = 'message',
descriptions: list = ['message'],
):
await info_logger(message, [str(description)])
await info_logger(message, descriptions)

async def command_callback(
message: types.Message,
description: str = 'command',
descriptions: list = ['command'],
):
await info_logger(message, ['command', str(description)],)
await info_logger(message, ['command'] + descriptions)

async def error_callback(
message: types.Message,
exception: Exception = None,
descriptions: list = ['error'],
):
await debug_logger(message, exception, descriptions)

async def exception_callback(
exception: Exception = None,
descriptions: list = ['error'],
error: Exception = None,
):
await debug_logger(descriptions, error)
await exception_logger(exception, descriptions)

async def any_message_callback(message: types.Message):
await info_logger(message, ['message', message.content_type])
await info_logger(
message,
['message', message.content_type, message.chat.type],
)

async def any_edited_message_callback(message: types.Message):
await info_logger(message, ['edited_message'])
await info_logger(message, ['edited_message', message.chat.type])

async def any_channel_post_callback(message: types.Message):
await info_logger(message, ['channel_post'])
Expand All @@ -136,4 +145,7 @@ async def any_update_callback(update):
await info_logger(update, ['update'])

async def any_error_callback(update, error):
await debug_logger(['error'], error)
if update:
await debug_logger(update, error, ['error', 'unhandled'])
else:
await exception_logger(error, ['error', 'unhandled'])
39 changes: 39 additions & 0 deletions matebot/aio_matebot/controllers/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
#
# Matebot
#
# Copyleft 2012-2020 Iuri Guilherme <https://github.com/iuriguilherme>,
# Matehackers <https://github.com/matehackers>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#

from aiogram import (
filters,
types,
)

## TODO Organizar em controllers
class IsReplyToIdFilter(filters.BoundFilter):
key = 'is_reply_to_id'

def __init__(self, is_reply_to_id):
self.is_reply_to_id = is_reply_to_id

async def check(self, msg: types.Message):
if msg.reply_to_message and (
msg.reply_to_message.from_user.id == self.is_reply_to_id):
return True
Loading

0 comments on commit 9a1b623

Please sign in to comment.