Passed
Branch master (dc2491)
by Anas
03:44 queued 02:00
created

modules.rate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 8

3 Functions

Rating   Name   Duplication   Size   Complexity  
A module_init() 0 4 2
A rate() 0 16 4
A ifint() 0 6 2
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
from telegram.ext import CommandHandler
4
from modules.logging import log_command
5
from random import random, seed
6
from datetime import datetime
7
8
9
def module_init(gd):
10
    commands = gd.config["commands"]
11
    for command in commands:
12
        gd.dp.add_handler(CommandHandler(command, rate, pass_args=True))
13
14
15
def ifint(number):
16
    if number.is_integer():
17
        number = int(number)
18
        return number
19
    else:
20
        return number
21
22
23
def rate(bot, update, args):
24
    current_time = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S")
25
    if update.message.reply_to_message is not None:
26
        if update.message.reply_to_message.text is not None:
27
            args = update.message.reply_to_message.text.split(" ")
28
    string = " ".join(args).lower()
29
    if string == "":
30
        seed()
31
    else:
32
        seed(string)
33
    rng = random() * 10
34
    rounded = round(rng * 2) / 2
35
    rating = str(ifint(rounded))
36
    update.message.reply_text("🤔 I rate this "+rating+"/10")
37
    print(current_time, ">", "/rate", ">", update.message.from_user.username)
38
    log_command(bot, update, current_time, "rate")
39