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

modules.nya   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A module_init() 0 9 2
A nya() 0 10 2
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
from telegram.ext.dispatcher import run_async
4
from telegram.ext import CommandHandler
5
from modules.logging import log_command
6
from telegram import ChatAction
7
from random import randint
8
from datetime import datetime
9
import os
10
11
12
def module_init(gd):
13
    global path, files, filecount
14
    path = gd.config["path"]
15
    commands = gd.config["commands"]
16
    for command in commands:
17
        gd.dp.add_handler(CommandHandler(command, nya))
18
    files = os.listdir(path)
19
    filecount = len(files)
20
    print("Nya images: ", filecount)
21
22
23
@run_async
24
def nya(bot, update):
25
    current_time = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S")
26
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
27
    rand = randint(0, filecount-1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable filecount does not seem to be defined.
Loading history...
28
    result = files[rand]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable files does not seem to be defined.
Loading history...
29
    with open(path+"/"+str(result), "rb") as f:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable path does not seem to be defined.
Loading history...
30
        update.message.reply_photo(f)
31
    print(current_time, ">", "/nya", ">", update.message.from_user.username)
32
    log_command(bot, update, current_time, "nya")
33