Total Complexity | 4 |
Total Lines | 46 |
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 telegram import ChatAction |
||
6 | import requests |
||
7 | import datetime |
||
8 | |||
9 | |||
10 | def module_init(gd): |
||
11 | commands = gd.config["commands"] |
||
12 | for command in commands: |
||
13 | gd.dp.add_handler(CommandHandler(command, toristats, pass_args=True)) |
||
14 | |||
15 | |||
16 | @run_async |
||
17 | def toristats(bot, update, args): |
||
18 | update.message.chat.send_action(ChatAction.TYPING) |
||
19 | user = args[0] |
||
20 | toristats = "http://forum.toribash.com/tori_stats.php?format=json" |
||
21 | full_link = toristats + "&username=" + user |
||
22 | r = requests.get(full_link) |
||
23 | try: |
||
24 | tori_json = r.json() |
||
25 | except: |
||
26 | update.message.reply_text("No such player") |
||
27 | return |
||
28 | |||
29 | userid = tori_json["userid"] |
||
30 | username = tori_json["username"] |
||
31 | qi = tori_json["qi"] |
||
32 | belt = tori_json["belt"] |
||
33 | clanname = tori_json["clanname"] |
||
34 | elo = tori_json["elo"] |
||
35 | winratio = tori_json["winratio"] |
||
36 | tc = tori_json["tc"] |
||
37 | lastact = str(datetime.datetime.fromtimestamp(int(tori_json["lastactivity"]))) |
||
38 | |||
39 | output = ("User ID: " + userid + "\nUsername: " + username + |
||
40 | "\nQi: " + str(qi) + ", " + belt + |
||
41 | "\nClan: " + clanname + |
||
42 | "\nWin Ratio: " + str(winratio)[:-2] + "%, " + str(elo)[:-4] + " elo" + |
||
43 | "\nToricredits: " + str(tc)) + "\nLast Active: " + lastact |
||
44 | update.message.reply_text(output) |
||
45 | print(datetime.datetime.now(), ">", "/toribash", ">", update.message.from_user.username) |
||
46 |