Skip to content

Commit acfd47c

Browse files
committed
pep8tting whole project, removing unused imports and code
1 parent a98c416 commit acfd47c

35 files changed

Lines changed: 219 additions & 203 deletions

tg_bot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44

55
import telegram.ext as tg
6+
67
from tg_bot._version import __version__
78

89
# enable logging
@@ -113,7 +114,6 @@
113114
DEFAULT_CHAT_ID = Config.DEFAULT_CHAT_ID
114115
VERSION = __version__
115116

116-
117117
SUDO_USERS.add(OWNER_ID)
118118

119119
updater = tg.Updater(TOKEN, workers=WORKERS)

tg_bot/__main__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
LOGGER,
3434
ALLOW_EXCL,
3535
DEFAULT_CHAT_ID,
36-
VERSION,
3736
)
38-
3937
# needed to dynamically load modules
4038
# NOTE: Module order is not guaranteed, specify that in the config file!
4139
from tg_bot.modules import ALL_MODULES
@@ -79,7 +77,6 @@
7977
In caso tu sia ancora mutato, invia questo comando: /CoCDone per essere sbloccato.\nOra puoi chattare nel gruppo e inviare messaggi :)\nSe hai ancora bisogno di me puoi
8078
usare il comando /help per più informazioni."""
8179

82-
8380
IMPORTED = {}
8481
MIGRATEABLE = []
8582
HELPABLE = {}
@@ -348,7 +345,7 @@ def send_settings(chat_id, user_id, user=False):
348345
user_id,
349346
"Queste sono le tue impostazioni attuali:" + "\n\n" + settings,
350347
parse_mode=ParseMode.MARKDOWN,
351-
)
348+
)
352349

353350
else:
354351
dispatcher.bot.send_message(

tg_bot/modules/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def __list_all_modules():
1717
to_load = LOAD
1818
if to_load:
1919
if not all(
20-
any(mod == module_name for module_name in all_modules)
21-
for mod in to_load
20+
any(mod == module_name for module_name in all_modules)
21+
for mod in to_load
2222
):
2323
LOGGER.error("Invalid loadorder names. Quitting.")
2424
quit(1)

tg_bot/modules/admin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def pin(bot: Bot, update: Update, args: List[str]) -> str:
153153
is_silent = True
154154
if len(args) >= 1:
155155
is_silent = not (
156-
args[0].lower() == "notify"
157-
or args[0].lower() == "loud"
158-
or args[0].lower() == "violent"
156+
args[0].lower() == "notify"
157+
or args[0].lower() == "loud"
158+
or args[0].lower() == "violent"
159159
)
160160

161161
if prev_message and is_group:

tg_bot/modules/afk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def reply_afk(bot: Bot, update: Update):
5555

5656
elif ent.type == MessageEntity.MENTION:
5757
user_id = get_user_id(
58-
message.text[ent.offset : ent.offset + ent.length]
58+
message.text[ent.offset: ent.offset + ent.length]
5959
)
6060
if not user_id:
6161
# Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?

tg_bot/modules/disable.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
DISABLE_OTHER = []
2323
ADMIN_CMDS = []
2424

25+
2526
class DisableAbleCommandHandler(CommandHandler):
2627
def __init__(self, command, callback, admin_ok=False, **kwargs):
2728
super().__init__(command, callback, **kwargs)
@@ -41,8 +42,8 @@ def check_update(self, update):
4142
if super().check_update(update):
4243
# Should be safe since check_update passed.
4344
command = update.effective_message.text_html.split(None, 1)[0][
44-
1:
45-
].split("@")[0]
45+
1:
46+
].split("@")[0]
4647

4748
# disabled, admincmd, user admin
4849
if sql.is_command_disabled(chat.id, command):
@@ -54,6 +55,7 @@ def check_update(self, update):
5455

5556
return False
5657

58+
5759
class DisableAbleRegexHandler(RegexHandler):
5860
def __init__(self, pattern, callback, friendly="", **kwargs):
5961
super().__init__(pattern, callback, **kwargs)
@@ -66,6 +68,7 @@ def check_update(self, update):
6668
chat.id, self.friendly
6769
)
6870

71+
6972
@run_async
7073
@user_admin
7174
def disable(bot: Bot, update: Update, args: List[str]):
@@ -89,6 +92,7 @@ def disable(bot: Bot, update: Update, args: List[str]):
8992
else:
9093
update.effective_message.reply_text("Cosa dovrei disabilitare?")
9194

95+
9296
@run_async
9397
@user_admin
9498
def enable(bot: Bot, update: Update, args: List[str]):
@@ -111,6 +115,7 @@ def enable(bot: Bot, update: Update, args: List[str]):
111115
else:
112116
update.effective_message.reply_text("Cosa dovrei abilitare?")
113117

118+
114119
@run_async
115120
@user_admin
116121
def list_cmds(bot: Bot, update: Update):
@@ -125,6 +130,7 @@ def list_cmds(bot: Bot, update: Update):
125130
else:
126131
update.effective_message.reply_text("Tutti i comandi sono abilitati.")
127132

133+
128134
# do not async
129135
def build_curr_disabled(chat_id: Union[str, int]) -> str:
130136
disabled = sql.get_all_disabled(chat_id)
@@ -136,24 +142,29 @@ def build_curr_disabled(chat_id: Union[str, int]) -> str:
136142
result += " - `{}`\n".format(escape_markdown(cmd))
137143
return "I seguenti comando sono attualmente ristretti:\n{}".format(result)
138144

145+
139146
@run_async
140147
def commands(bot: Bot, update: Update):
141148
chat = update.effective_chat
142149
update.effective_message.reply_text(
143150
build_curr_disabled(chat.id), parse_mode=ParseMode.MARKDOWN
144151
)
145152

153+
146154
def __stats__():
147155
return "{} comandi disabilitati, in {} chats.".format(
148156
sql.num_disabled(), sql.num_chats()
149157
)
150158

159+
151160
def __migrate__(old_chat_id, new_chat_id):
152161
sql.migrate_chat(old_chat_id, new_chat_id)
153162

163+
154164
def __chat_settings__(chat_id, user_id):
155165
return build_curr_disabled(chat_id)
156166

167+
157168
__mod_name__ = "Command disabling"
158169

159170
__help__ = """

tg_bot/modules/global_bans.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ def check_and_ban(update, user_id, should_message=True):
267267
def enforce_gban(bot: Bot, update: Update):
268268
# Not using @restrict handler to avoid spamming - just ignore if cant gban.
269269
if (
270-
sql.does_chat_gban(update.effective_chat.id)
271-
and update.effective_chat.get_member(bot.id).can_restrict_members
270+
sql.does_chat_gban(update.effective_chat.id)
271+
and update.effective_chat.get_member(bot.id).can_restrict_members
272272
):
273273
user = update.effective_user # type: Optional[User]
274274
chat = update.effective_chat # type: Optional[Chat]

tg_bot/modules/helper_funcs/chat_status.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def can_delete(chat: Chat, bot_id: int) -> bool:
1212

1313
def is_user_ban_protected(chat: Chat, user_id: int, member: ChatMember = None) -> bool:
1414
if (
15-
chat.type == "private"
16-
or user_id in SUDO_USERS
17-
or user_id in WHITELIST_USERS
18-
or chat.all_members_are_administrators
15+
chat.type == "private"
16+
or user_id in SUDO_USERS
17+
or user_id in WHITELIST_USERS
18+
or chat.all_members_are_administrators
1919
):
2020
return True
2121

@@ -26,9 +26,9 @@ def is_user_ban_protected(chat: Chat, user_id: int, member: ChatMember = None) -
2626

2727
def is_user_admin(chat: Chat, user_id: int, member: ChatMember = None) -> bool:
2828
if (
29-
chat.type == "private"
30-
or user_id in SUDO_USERS
31-
or chat.all_members_are_administrators
29+
chat.type == "private"
30+
or user_id in SUDO_USERS
31+
or chat.all_members_are_administrators
3232
):
3333
return True
3434

tg_bot/modules/helper_funcs/extraction.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def extract_user(message: Message, args: List[str]) -> Optional[int]:
2323

2424

2525
def extract_user_and_text(
26-
message: Message, args: List[str]
26+
message: Message, args: List[str]
2727
) -> (Optional[int], Optional[str]):
2828
prev_message = message.reply_to_message
2929
split_text = message.text.split(None, 1)
@@ -45,7 +45,7 @@ def extract_user_and_text(
4545
if entities and ent and ent.offset == len(message.text) - len(text_to_parse):
4646
ent = entities[0]
4747
user_id = ent.user.id
48-
text = message.text[ent.offset + ent.length :]
48+
text = message.text[ent.offset + ent.length:]
4949

5050
elif len(args) >= 1 and args[0][0] == "@":
5151
user = args[0]
@@ -94,7 +94,7 @@ def extract_user_and_text(
9494

9595
def extract_text(message) -> str:
9696
return (
97-
message.text
98-
or message.caption
99-
or (message.sticker.emoji if message.sticker else None)
97+
message.text
98+
or message.caption
99+
or (message.sticker.emoji if message.sticker else None)
100100
)

tg_bot/modules/helper_funcs/handlers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ def __init__(self, command, callback, **kwargs):
1212

1313
def check_update(self, update):
1414
if isinstance(update, Update) and (
15-
update.message or update.edited_message and self.allow_edited
15+
update.message or update.edited_message and self.allow_edited
1616
):
1717
message = update.message or update.edited_message
1818

1919
if message.text and len(message.text) > 1:
2020
fst_word = message.text_html.split(None, 1)[0]
2121
if len(fst_word) > 1 and any(
22-
fst_word.startswith(start) for start in CMD_STARTERS
22+
fst_word.startswith(start) for start in CMD_STARTERS
2323
):
2424
command = fst_word[1:].split("@")
2525
command.append(
@@ -33,8 +33,8 @@ def check_update(self, update):
3333
res = self.filters(message)
3434

3535
return res and (
36-
command[0].lower() in self.command
37-
and command[1].lower() == message.bot.username.lower()
36+
command[0].lower() in self.command
37+
and command[1].lower() == message.bot.username.lower()
3838
)
3939

4040
return False

0 commit comments

Comments
 (0)