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

modules.rate.ifint()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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