-
Notifications
You must be signed in to change notification settings - Fork 6
/
on_pvt.py
148 lines (134 loc) · 6.63 KB
/
on_pvt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import tables, strings, util, telegram
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, ChatAction
from peewee import *
from emoji import emojize
from telegram.ext import CallbackContext
import cacheable, json, os
from datetime import date
def start_pvt(update: Update, context: CallbackContext):
try:
tables.User.get(tables.User.user_id == update.message.from_user.id)
text = strings.Start.start_pvt
except DoesNotExist:
text = strings.Global.user_not_exist
finally:
text += strings.Start.start_id.format(update.message.from_user.id, update.message.chat_id)
context.bot.send_message(chat_id=update.message.chat_id, text=text, parse_mode=telegram.ParseMode.MARKDOWN)
@util.send_action(ChatAction.TYPING)
def dci(update: Update, context: CallbackContext):
args = update.message.text.split(" ")
if len(args) == 1:
text = strings.Dci.dci_invalid
else:
dci = args[1]
try:
if dci.isdigit() and not dci.startswith('-'):
user = tables.User.get(tables.User.user_id == update.message.from_user.id)
user.dci = dci
user.save()
text = strings.Dci.dci_set.format(dci)
else:
text = strings.Dci.dci_invalid
except DoesNotExist:
text = strings.Global.user_not_exist
context.bot.send_message(chat_id=update.message.chat_id,
text=text,
parse_mode=telegram.ParseMode.MARKDOWN)
@util.send_action(ChatAction.TYPING)
def name(update: Update, context: CallbackContext):
args = update.message.text.split(" ", 1)
if len(args) == 1:
context.bot.send_message(chat_id=update.message.chat_id,
text=strings.Name.name_invalid,
parse_mode=telegram.ParseMode.MARKDOWN)
else:
name = args[1]
try:
user = tables.User.get(tables.User.user_id == update.message.from_user.id)
user.name = name
user.save()
context.bot.send_message(chat_id=update.message.chat_id,
text=strings.Name.name_set.format(name),
parse_mode=telegram.ParseMode.MARKDOWN)
except DoesNotExist:
context.bot.send_message(chat_id=update.message.chat_id,
text=strings.Global.user_not_exist,
parse_mode=telegram.ParseMode.MARKDOWN)
@util.send_action(ChatAction.TYPING)
def arena(update: Update, context: CallbackContext):
args = update.message.text.split(" ", 1)
if len(args) == 1:
context.bot.send_message(chat_id=update.message.chat_id,
text=strings.Arena.arena_invalid,
parse_mode=telegram.ParseMode.MARKDOWN)
else:
arena = args[1]
try:
user = tables.User.get(tables.User.user_id == update.message.from_user.id)
user.arena = arena
user.save()
context.bot.send_message(chat_id=update.message.chat_id,
text=strings.Arena.arena_set.format(arena),
parse_mode=telegram.ParseMode.MARKDOWN)
except DoesNotExist:
context.bot.send_message(chat_id=update.message.chat_id,
text=strings.Global.user_not_exist,
parse_mode=telegram.ParseMode.MARKDOWN)
@util.send_action(ChatAction.TYPING)
def logparser(update: Update, context: CallbackContext):
file_id = update.message.document.file_id
newFile = context.bot.get_file(file_id)
filename = './temp/{}.log'.format(update.message.from_user.id)
newFile.download(filename)
with open(filename, "r") as file:
for line in file:
if "<== PlayerInventory.GetPlayerCardsV3" in line:
json_object = line[line.index("{"):]
player_cards = json.loads(json_object)
# print(player_cards)
if "<== PlayerInventory.GetPlayerInventory" in line:
json_object = line[line.index("{"):]
player_inventory = json.loads(json_object)
text = strings.Log.log_result_parsing.format(date.today().strftime("%d/%m/%Y"),
player_inventory['payload']['vaultProgress'],
player_inventory['payload']['gems'],
player_inventory['payload']['gold'])
context.bot.send_message(chat_id=update.message.chat_id,
text=emojize(text, use_aliases=True),
parse_mode=telegram.ParseMode.MARKDOWN,
reply_to_message_id=update.message.message_id)
break
os.remove(filename)
@util.send_action(ChatAction.TYPING)
def help_pvt(update: Update, context: CallbackContext):
if update.message.from_user.id in cacheable.get_admin_ids(context.bot):
button_list = [InlineKeyboardButton("user", callback_data="help_user"),
InlineKeyboardButton("admin", callback_data="help_admin")]
reply_markup = InlineKeyboardMarkup(util.build_menu(button_list, n_cols=2))
text = strings.Help.admin_help
context.bot.send_message(chat_id=update.message.chat_id,
text=emojize(text, use_aliases=True),
parse_mode=telegram.ParseMode.MARKDOWN,
reply_markup=reply_markup)
else:
text = strings.Help.user_help
context.bot.send_message(chat_id=update.message.chat_id,
text=emojize(text, use_aliases=True),
parse_mode=telegram.ParseMode.MARKDOWN)
def help_cb(update: Update, context: CallbackContext):
query = update.callback_query
button_list = [InlineKeyboardButton("user", callback_data="help_user"),
InlineKeyboardButton("admin", callback_data="help_admin")]
reply_markup = InlineKeyboardMarkup(util.build_menu(button_list, n_cols=2))
if "help_user" in query.data:
reply = strings.Help.user_help
pass
else:
reply = strings.Help.admin_help
pass
try:
context.bot.edit_message_text(text=reply, chat_id=query.message.chat_id,
message_id=query.message.message_id, reply_markup=reply_markup,
parse_mode=telegram.ParseMode.MARKDOWN)
except telegram.error.BadRequest:
context.bot.answer_callback_query(callback_query_id=update.callback_query.id)