Total Complexity | 4 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
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) |
||
|
|||
28 | result = files[rand] |
||
29 | with open(path+"/"+str(result), "rb") as f: |
||
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 |