Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавление бд и много чего другого #12

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/python-publish.yml
@@ -0,0 +1,36 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
14 changes: 10 additions & 4 deletions README.md
@@ -1,17 +1,23 @@
# 👹 Samurai Telegram Bot
Simple, yet effective moderator bot for telegram. With reports, logs, profanity filter and more :3

Simple, yet effective moderator bot for telegram. With reports, logs, profanity filter and more :3

# Description

Personal bot, made for easy chat auto-moderation.
Adds reporting functionality, profanity filtering (both english & russian languages are supported), logging system via private channel and much more!
More of that, the bot code & functions can be easily extended and/or limited as you prefer.
Adds reporting functionality, profanity filtering (both english & russian languages are supported), logging system via
private channel and much more!
More of that, the bot code & functions can be easily extended and/or limited as you prefer.

*The code has NOT been polished and is provided "as is". There are a lot of code that are redundant and there are tons of improvements that can be made.*
*The code has NOT been polished and is provided "as is". There are a lot of code that are redundant and there are tons
of improvements that can be made.*

# ToDo

https://trello.com/b/MbwAxjd1/xobot-official

## Credits

https://github.com/masteroncluster/py-censure - Profanity filter we used as a base
https://github.com/MasterGroosha/telegram-report-bot - Reports system we used as a base

Expand Down
8 changes: 5 additions & 3 deletions announcements.py
Expand Up @@ -4,13 +4,15 @@
import asyncio
import aioschedule as schedule


async def announce(message):
await dispatcher.dp.bot.send_message(configurator.config.groups.main, message)
await dispatcher.dp.bot.send_message(configurator.config.groups.main, message)


async def scheduler():
for i in localization.get_string('announcements'):
schedule.every(i['every']).seconds.do(announce, i['message'])
schedule.every(i['every']).seconds.do(announce, i['message'])

while True:
await schedule.run_pending()
await asyncio.sleep(2)
await asyncio.sleep(2)
6 changes: 3 additions & 3 deletions bot.py
Expand Up @@ -5,6 +5,6 @@
import asyncio

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.create_task(announcements.scheduler())
executor.start_polling(dp, skip_updates=True)
loop = asyncio.get_event_loop()
loop.create_task(announcements.scheduler())
executor.start_polling(dp, skip_updates=True)
2 changes: 1 addition & 1 deletion censure/censure/__init__.py
@@ -1,4 +1,4 @@
from .base import Censor
from .helper import CensorHelper

__all__ = ['Censor', 'CensorHelper']
__all__ = ['Censor', 'CensorHelper']
2 changes: 1 addition & 1 deletion censure/censure/base.py
Expand Up @@ -87,7 +87,7 @@ def __init__(self, value=None, token_type=None):
head = head[0].lower()[1:]

if not token_type:
token_type = 'to' # open type ie <a...>
token_type = 'to' # open type ie <a...>
# should derive from value
if head[0] == '/':
head = head[1:]
Expand Down
1 change: 0 additions & 1 deletion censure/censure/lang/en/__init__.py
@@ -1,5 +1,4 @@
from . import constants
from . import patterns


__all__ = ['constants', 'patterns']
4 changes: 0 additions & 4 deletions censure/censure/lang/en/constants.py
Expand Up @@ -3,12 +3,10 @@

from __future__ import unicode_literals


EXCLUDES_DATA = {

}


EXCLUDES_CORE = {

}
Expand Down Expand Up @@ -127,7 +125,6 @@
'bullshit': '^bullshit$',
'butt': '^butt((plug)|(pirate)|($))',


'clit': '^clit(($)|(or)|(face))',
'cum': '^cum(($)|(bubble)|(dumpster)|(guzzler)|(jockey)|(slut)|(tart))',
'cunni': '^cunni(($)|(e)|(lingus))',
Expand Down Expand Up @@ -169,7 +166,6 @@
'whore': '^whore(bag|face|$)',
}


BAD_SEMI_PHRASES = (
'suckmydick',
'sickmyduck',
Expand Down
34 changes: 16 additions & 18 deletions censure/censure/lang/en/patterns.py
Expand Up @@ -2,31 +2,29 @@
from __future__ import unicode_literals
import re

PAT_EUML = re.compile('&[Ee][Uu][Mm][Ll];') # e
PAT_IUML = re.compile('&[Uu][Uu][Mm][Ll];') # и
PAT_AUML = re.compile('&[Aa][Uu][Mm][Ll];') # а
PAT_OUML = re.compile('&[Oo][Uu][Mm][Ll];') # о
PAT_YUML = re.compile('&[Yy][Uu][Mm][Ll];') # у

PAT_EUML = re.compile('&[Ee][Uu][Mm][Ll];') # e
PAT_IUML = re.compile('&[Uu][Uu][Mm][Ll];') # и
PAT_AUML = re.compile('&[Aa][Uu][Mm][Ll];') # а
PAT_OUML = re.compile('&[Oo][Uu][Mm][Ll];') # о
PAT_YUML = re.compile('&[Yy][Uu][Mm][Ll];') # у

PAT_CENT = re.compile('&[Cc][Ee][Nn][Tt];') # c
PAT_CODE203 = re.compile('&#203;') # e
PAT_CODE162 = re.compile('&#162;') # c
PAT_CODE120 = re.compile('&#120;') # х
PAT_CODE121 = re.compile('&#121;') # у

PAT_CENT = re.compile('&[Cc][Ee][Nn][Tt];') # c
PAT_CODE203 = re.compile('&#203;') # e
PAT_CODE162 = re.compile('&#162;') # c
PAT_CODE120 = re.compile('&#120;') # х
PAT_CODE121 = re.compile('&#121;') # у

PATTERNS_REPLACEMENTS = (
(PAT_EUML, 'e'), # euml
(PAT_IUML, 'u'), # iuml
(PAT_AUML, 'a'), # auml
(PAT_OUML, 'o'), # ouml
(PAT_YUML, 'y'), # yuml
(PAT_EUML, 'e'), # euml
(PAT_IUML, 'u'), # iuml
(PAT_AUML, 'a'), # auml
(PAT_OUML, 'o'), # ouml
(PAT_YUML, 'y'), # yuml

(PAT_CODE120, 'x'),
(PAT_CODE121, 'y'),
(PAT_CODE203, 'e'),

(PAT_CENT, 'c'), # cent
(PAT_CENT, 'c'), # cent
(PAT_CODE162, 'c'),
)
1 change: 0 additions & 1 deletion censure/censure/lang/ru/__init__.py
@@ -1,5 +1,4 @@
from . import constants
from . import patterns


__all__ = ['constants', 'patterns']
4 changes: 0 additions & 4 deletions censure/censure/lang/ru/constants.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


EXCLUDES_DATA = {
'а': [
'автомоб',
Expand Down Expand Up @@ -419,7 +418,6 @@
]
}


EXCLUDES_CORE = {
'боле': 'боле',
'гре#1': '^.{0,3}греб$',
Expand Down Expand Up @@ -489,7 +487,6 @@
'япуч': 'яп[п]?уч'
}


FOUL_DATA = {
'а': [
'^абанамат',
Expand Down Expand Up @@ -1016,7 +1013,6 @@
]
}


BAD_SEMI_PHRASES = (
'анепош[е]?л[и]?бы[вт]ы',
'еханыйбабай',
Expand Down
95 changes: 46 additions & 49 deletions censure/censure/lang/ru/patterns.py
Expand Up @@ -2,77 +2,74 @@
from __future__ import unicode_literals
import re

PAT_EUML = re.compile('&[Ee][Uu][Mm][Ll];') # e
PAT_IUML = re.compile('&[Uu][Uu][Mm][Ll];') # и
PAT_AUML = re.compile('&[Aa][Uu][Mm][Ll];') # а
PAT_OUML = re.compile('&[Oo][Uu][Mm][Ll];') # о
PAT_YUML = re.compile('&[Yy][Uu][Mm][Ll];') # у

PAT_EUML = re.compile('&[Ee][Uu][Mm][Ll];') # e
PAT_IUML = re.compile('&[Uu][Uu][Mm][Ll];') # и
PAT_AUML = re.compile('&[Aa][Uu][Mm][Ll];') # а
PAT_OUML = re.compile('&[Oo][Uu][Mm][Ll];') # о
PAT_YUML = re.compile('&[Yy][Uu][Mm][Ll];') # у
PAT_CENT = re.compile('&[Cc][Ee][Nn][Tt];') # c
PAT_CODE203 = re.compile('&#203;') # e
PAT_CODE162 = re.compile('&#162;') # c
PAT_CODE120 = re.compile('&#120;') # х
PAT_CODE121 = re.compile('&#121;') # у

PAT_CENT = re.compile('&[Cc][Ee][Nn][Tt];') # c
PAT_CODE203 = re.compile('&#203;') # e
PAT_CODE162 = re.compile('&#162;') # c
PAT_CODE120 = re.compile('&#120;') # х
PAT_CODE121 = re.compile('&#121;') # у
PAT_AS_I = re.compile(r'\|\\\|') # И
PAT_AS_L = re.compile(r'/\\') # Л

PAT_AS_I = re.compile(r'\|\\\|') # И
PAT_AS_L = re.compile(r'/\\') # Л
PAT_AS_X1 = re.compile(r'><') # Х
PAT_AS_X2 = re.compile(r'><') # Х
PAT_AS_X3 = re.compile('\)\(') # Х
PAT_AS_X4 = re.compile('}{') # Х

PAT_AS_X1 = re.compile(r'><') # Х
PAT_AS_X2 = re.compile(r'><') # Х
PAT_AS_X3 = re.compile('\)\(') # Х
PAT_AS_X4 = re.compile('}{') # Х
PAT_AS_J1 = re.compile('>\|<') # Ж
PAT_AS_J2 = re.compile('}\|{') # Ж

PAT_AS_J1 = re.compile('>\|<') # Ж
PAT_AS_J2 = re.compile('}\|{') # Ж

PAT_AS_Y1 = re.compile('`/') # Y
PAT_AS_Y2 = re.compile('\-/') # Y
PAT_AS_Y3 = re.compile('`\-/') # Y

PAT_AS_YY1 = re.compile('b\|') # ы
PAT_AS_YY2 = re.compile('bI') # ы
PAT_AS_YY3 = re.compile('bl') # ы
PAT_AS_Y1 = re.compile('`/') # Y
PAT_AS_Y2 = re.compile('\-/') # Y
PAT_AS_Y3 = re.compile('`\-/') # Y

PAT_AS_YY1 = re.compile('b\|') # ы
PAT_AS_YY2 = re.compile('bI') # ы
PAT_AS_YY3 = re.compile('bl') # ы

PAT_PI = re.compile('3[\.,]14[\d]*')
PAT_E = re.compile('2[\.,]72[\d]*')
PAT_PREP = re.compile('(а[х]?)|(в)|([вмт]ы)|(д[ао])|(же)|(за)')


PATTERNS_REPLACEMENTS = (
(PAT_EUML, 'е'), # euml
(PAT_IUML, 'и'), # iuml
(PAT_AUML, 'а'), # auml
(PAT_OUML, 'о'), # ouml
(PAT_YUML, 'у'), # yuml
(PAT_EUML, 'е'), # euml
(PAT_IUML, 'и'), # iuml
(PAT_AUML, 'а'), # auml
(PAT_OUML, 'о'), # ouml
(PAT_YUML, 'у'), # yuml

(PAT_CODE203, 'е'),

(PAT_CENT, 'с'), # cent
(PAT_CENT, 'с'), # cent
(PAT_CODE162, 'с'),

(PAT_AS_I, 'и'), # as И
(PAT_AS_L, 'л'), # as Л
(PAT_AS_I, 'и'), # as И
(PAT_AS_L, 'л'), # as Л

(PAT_AS_X1, 'х'), # as Х
(PAT_AS_X2, 'х'), # as Х
(PAT_AS_X3, 'х'), # as Х
(PAT_AS_X4, 'х'), # as Х
(PAT_AS_X1, 'х'), # as Х
(PAT_AS_X2, 'х'), # as Х
(PAT_AS_X3, 'х'), # as Х
(PAT_AS_X4, 'х'), # as Х

(PAT_AS_J1, 'ж'), # as ж
(PAT_AS_J2, 'ж'), # as ж
(PAT_AS_J1, 'ж'), # as ж
(PAT_AS_J2, 'ж'), # as ж

(PAT_AS_Y1, 'y'), # as y
(PAT_AS_Y2, 'y'), # as y
(PAT_AS_Y3, 'y'), # as y
(PAT_AS_Y1, 'y'), # as y
(PAT_AS_Y2, 'y'), # as y
(PAT_AS_Y3, 'y'), # as y

(PAT_AS_YY1, 'ы'), # as ы
(PAT_AS_YY2, 'ы'), # as ы
(PAT_AS_YY3, 'ы'), # as ы
(PAT_AS_YY1, 'ы'), # as ы
(PAT_AS_YY2, 'ы'), # as ы
(PAT_AS_YY3, 'ы'), # as ы

(PAT_CODE120, 'х'),
(PAT_CODE121, 'у'),
(PAT_PI, 'пи'), # 3.14...
(PAT_E, 'е'), # 2.72...
(PAT_PI, 'пи'), # 3.14...
(PAT_E, 'е'), # 2.72...
)
1 change: 1 addition & 0 deletions censure/censure/tests/base.py
Expand Up @@ -9,6 +9,7 @@

from censure.base import Censor, CensorException
from censure.lang.common import constants, patterns

# from censure.tests.data import (
# SIMPLE_OBSCENE_WORDS, E_OBSCENE_WORDS, PI_OBSCENE_WORDS,
# OBSCENE_HTML_LINES,
Expand Down
1 change: 0 additions & 1 deletion censure/censure/tests/ru/data.py
Expand Up @@ -2,7 +2,6 @@
from __future__ import unicode_literals
from censure.lang.common.constants import BEEP


SIMPLE_OBSCENE_WORDS = (
'пидорги',
'ебланаи',
Expand Down
10 changes: 5 additions & 5 deletions censure/censure/tests/ru/test_base.py
Expand Up @@ -8,11 +8,11 @@
class CensorInternalsTestCase(TestCaseRu):
def test__is_pi_or_e_word(self):
for w, result in (
('2.72', True),
('3.14', True),
('2.71', False),
('3.15', False),
('5.15', False),
('2.72', True),
('3.14', True),
('2.71', False),
('3.15', False),
('5.15', False),
):
if self._dice(): # prefix
w = '{}{}'.format(self._get_random_word(), w)
Expand Down