Skip to content

Commit f7427ef

Browse files
committed
Refactor py files according to PEP8
1 parent 979300f commit f7427ef

6 files changed

Lines changed: 273 additions & 202 deletions

File tree

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ name = "pypi"
66
[packages]
77
python-telegram-bot = "*"
88
prettyconf = "*"
9+
yapf = "*"
910

1011
[dev-packages]
1112
"flake8" = "*"
1213
"fabric3" = "*"
1314
rope = "*"
1415
pytest = "*"
16+
yapf = "*"
1517

1618
[requires]
1719
python_version = "3.6"

Pipfile.lock

Lines changed: 247 additions & 185 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def welcome(bot: Bot, update: Update):
1515
"-> It could be kindly removed 🗑"
1616
else:
1717
if utils.is_bot(new_member):
18-
bot.delete_message(update.message.chat_id, update.message.message_id)
18+
bot.delete_message(update.message.chat_id,
19+
update.message.message_id)
1920
if bot.kick_chat_member(update.message.chat_id, new_member.id):
2021
msg = (f"*{new_member.username}* has been banned because I "
2122
"considered it was a bot. ")

config.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313

1414
# A username longer than this will be considered non-human
1515
# - Allowed values: An integer larger than 1
16-
MAX_HUMAN_USERNAME_LENGTH = config('MAX_HUMAN_USERNAME_LENGTH', int, default=100)
16+
MAX_HUMAN_USERNAME_LENGTH = config('MAX_HUMAN_USERNAME_LENGTH',
17+
int,
18+
default=100)
1719

1820

19-
# We have found, through empiric evidence, that a large ration of Chinese characters
20-
# usually indicates the user is a spammer or bot.
21-
# This sets the maximum allowed percent of Chinese characters before considering the
22-
# user a bot.
21+
# We have found, through empiric evidence, that a large ration of Chinese
22+
# characters # usually indicates the user is a spammer or bot.
23+
# This sets the maximum allowed percent of Chinese characters before
24+
# considering the # user a bot.
2325
# - Allowed values: A float from 0 to 1
24-
MAX_CHINESE_CHARS_PERCENT = config('MAX_CHINESE_CHARS_PERCENT', float, default=0.15)
26+
MAX_CHINESE_CHARS_PERCENT = config('MAX_CHINESE_CHARS_PERCENT',
27+
float,
28+
default=0.15)
2529

2630

2731
def bot_replies_enabled() -> bool:

test/test_bot_detection.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
@pytest.mark.parametrize('char_num', range(32, 256))
99
def test_all_chars_under_255_must_pass(char_num):
10-
char = chr(char_num)
11-
assert not utils.is_chinese(char)
10+
char = chr(char_num)
11+
assert not utils.is_chinese(char)
1212

1313

1414
@pytest.mark.parametrize('spanish_char', 'áéíóúüñçÁÉÍÓÚÜÑÇ')
@@ -78,11 +78,12 @@ def test_is_not_bot():
7878

7979

8080
def test_is_bot_real_sample():
81-
name = ('[VX.QQ同号253239090]电报社群增粉仅1毛,量大价优,可指定群指定筛选条件'
82-
'及速度,提供明细报表[群发私发][社区运营][成品账号]欢迎项目方交易所洽'
83-
'谈合作,诚招全球代理 ALL MARKET BEST PRICE FOR WORLDWIDE REAL n ACTIVE'
84-
' TELEGRAM GROUP(CHANNEL) HUMAN MEMBERS,QUALITY AND QUANTITY'
85-
' GUARANTEED[Telegram:marvelwork/Email:smartelegram at outlook.com]')
81+
name = (
82+
'[VX.QQ同号253239090]电报社群增粉仅1毛,量大价优,可指定群指定筛选条件'
83+
'及速度,提供明细报表[群发私发][社区运营][成品账号]欢迎项目方交易所洽'
84+
'谈合作,诚招全球代理 ALL MARKET BEST PRICE FOR WORLDWIDE REAL n ACTIVE'
85+
' TELEGRAM GROUP(CHANNEL) HUMAN MEMBERS,QUALITY AND QUANTITY'
86+
' GUARANTEED[Telegram:marvelwork/Email:smartelegram at outlook.com]')
8687
user = Mock(first_name=name)
8788
assert utils.is_bot(user)
8889

utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def too_much_chinese_chars(s):
2626
letters = list(s)
2727
num_chinese_chars = sum([is_chinese(c) for c in letters])
2828
percent = num_chinese_chars / len(letters)
29-
return percent > config.MAX_CHINESE_CHARS_PERCENT # More than allowed
30-
# chars are Chinese
29+
# More than allowed chars are Chinese
30+
return percent > config.MAX_CHINESE_CHARS_PERCENT
3131

3232

3333
def is_valid_name(user: User):
@@ -84,7 +84,8 @@ def triggers_reply(message: str) -> typing.Optional[BotReplySpec]:
8484
# When a match is found, check if the bot will reply based on its
8585
# reply likelihood
8686
if not isinstance(bot_reply, str):
87-
# If value is a list then pick random string from multiple values:
87+
# If value is a list then pick random string from
88+
# multiple values:
8889
bot_reply = random.choice(bot_reply)
8990
return BotReplySpec(message, match.group(0), bot_reply)
9091
return None

0 commit comments

Comments
 (0)