Passed
Push — master ( 9bfda5...dc2491 )
by Anas
02:12
created

modules.leetspeak.leet()   B

Complexity

Conditions 7

Size

Total Lines 20
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
nop 3
dl 0
loc 20
rs 8
c 0
b 0
f 0
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
from modules.logging import log_command
4
from telegram.ext import CommandHandler
5
from datetime import datetime
6
from functools import reduce
7
8
9
def module_init(gd):
10
    global leet_dictionary, extensions
11
    leet_dictionary = gd.config["leet_dictionary"]
12
    commands = gd.config["commands"]
13
    for command in commands:
14
        gd.dp.add_handler(CommandHandler(command, leet, pass_args=True))
15
16
17
def leet(bot, update, args):
18
    current_time = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S")
19
    if update.message.reply_to_message is not None:
20
        args = update.message.reply_to_message.text
21
        args = args.split(" ")
22
    text_leet = " ".join(args).lower()
23
    if text_leet == "":
24
        return
25
    replace_dict = []
26
    with open(leet_dictionary, "r", encoding="UTF-8") as file:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable leet_dictionary does not seem to be defined.
Loading history...
27
        for i in file.readlines():
28
            tmp = i.split(",")
29
            try:
30
                replace_dict.append((tmp[0], tmp[1]))
31
            except:
32
                pass
33
    text_leet = reduce(lambda a, kv: a.replace(*kv), replace_dict, text_leet)
34
    update.message.reply_text(text_leet)
35
    print(current_time, ">", "/leetspeak", ">", update.message.from_user.username)
36
    log_command(bot, update, current_time, "leetspeak")
37