Completed
Push — master ( 82b9d3...7dbca0 )
by Anas
01:07
created

leet()   B

Complexity

Conditions 7

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 7
c 3
b 0
f 0
dl 0
loc 18
rs 7.3333
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
from telegram.ext import CommandHandler
4
from functools import reduce
5
import datetime
6
import yaml
7
8
# import path
9
with open("config.yml", "r") as f:
10
    leet_dictionary = yaml.load(f)["path"]["leet_dictionary"]
11
12
13
def handler(dp):
14
    dp.add_handler(CommandHandler("leet", leet, pass_args=True))
15
16
17
def leet(bot, update, args):
0 ignored issues
show
Unused Code introduced by
The argument bot seems to be unused.
Loading history...
18
    if update.message.reply_to_message is not None:
19
        args = update.message.reply_to_message.text
20
        args = args.split(" ")
21
    text_leet = " ".join(args).lower()
22
    if text_leet == "":
23
        return
24
    replace_dict = []
25
    with open(leet_dictionary, "r") as file:
26
        for i in file.readlines():
27
            tmp = i.split(",")
28
            try:
29
                replace_dict.append((tmp[0], tmp[1]))
30
            except:
31
                pass
32
    text_leet = reduce(lambda a, kv: a.replace(*kv), replace_dict, text_leet)
33
    update.message.reply_text(text_leet)
34
    print(datetime.datetime.now(), ">>>", "Done leetspeak", ">>>", update.message.from_user.username)
35