aboutsummaryrefslogtreecommitdiffstats
path: root/telebot.py
blob: 47dfdf1e09d5fb9ac9f7a8171a55bc5ad94937fc (plain) (blame)
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
#!/usr/bin/python3

import argparse
import code
import readline
import signal
import sys
from telegram.ext import Updater, CommandHandler
import logging
import imp
import json
sys.path.insert(0, "./python")
from deviutil import Demon_Father
hived = imp.load_source("hived", "./hived")
from hived import networth, highpercentdump_bot
sys.path.insert(0, "/home/rooot/devi/kaminokumo")
kaminokumo = imp.load_source("kaminokumo", "/home/rooot/devi/kaminokumo")
from kaminokumo import mrg import json
import threading
from io import TextIOWrapper, BytesIO

telekey_json = "./telekey.json"
json_key = json.load(open(telekey_json))
API_TOKEN = json_key['telekey']

class Mg_thread(threading.Thread):
    def __init__(self, bot, update):
        self.bot = bot
        self.update = update

    def run(self):
        url = json.load(open("/home/bloodstalker/extra/kaminokumo/data.json"))
        res = mrg(url["1"])
        text_str = str()
        if res: text_str = "marge is up"
        else: text_str = "no marge"
        res = mrg(url["2"])
        text_str = str()
        if res: text_str = "obk is up"
        else: text_str = "no obk"
        self.bot.send_message(chat_id=self.update.message.chat_id, text=text_str)

def start(bot, update):
    bot.send_message(chat_id=update.message.chat_id, text="Hey... nice to make your acquaintance.")

def net(bot, update):
    total = networth()
    bot.send_message(chat_id=update.message.chat_id, text=total)

def high(bot, update):
    total = highpercentdump_bot()
    total_str = "".join(total)
    bot.send_message(chat_id=update.message.chat_id, text=total_str)

def mg(bot, update):
    url = json.load(open("/home/bloodstalker/extra/kaminokumo/data.json"))
    res = mrg(url["1"])
    text_str = str()
    if res: text_str += "marge is up"
    else: text_str += "no marge\t"
    res = mrg(url["2"])
    if res: text_str += "obk is up"
    else: text_str += "no obk\t"
    bot.send_message(chat_id=update.message.chat_id, text=text_str)

def generic(bot, update, args):
    import mushi
    print(repr(args))
    old_stdout = sys.stdout
    sys.stdout = TextIOWrapper(BytesIO(), sys.stdout.encoding)
    mushi.main(args)
    sys.stdout.seek(0)
    out = sys.stdout.read()
    print(repr(out))
    bot.send_message(chat_id=update.message.chat_id, text=out)
    sys.stdout.close()
    sys.stdout = old_stdout

class Argparser(object):
    def __init__(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("--string", type=str, help="string")
        parser.add_argument("--bool", action="store_true", help="bool", default=False)
        parser.add_argument("--dbg", action="store_true", help="debug", default=False)
        self.args = parser.parse_args()

class Demon(Demon_Father):
    def run(self):
        updater = Updater(token=API_TOKEN)
        bot = updater.bot
        dispatcher = updater.dispatcher
        logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
        start_handler = CommandHandler("start", start)
        net_handler = CommandHandler("net", net)
        high_handler = CommandHandler("high", high)
        mg_handler = CommandHandler("mg", mg)
        generic_handler = CommandHandler("cc", generic, pass_args=True)
        dispatcher.add_handler(start_handler)
        dispatcher.add_handler(net_handler)
        dispatcher.add_handler(high_handler)
        dispatcher.add_handler(mg_handler)
        dispatcher.add_handler(generic_handler)
        updater.start_polling()

# write code here
def premain(argparser):
    #here
    pidfile = open("/tmp/telebot_temp", "w")
    demon = Demon(pidfile)
    demon.run()

def main():
    argparser = Argparser()
    if argparser.args.dbg:
        try:
            premain(argparser)
        except:
            variables = globals().copy()
            variables.update(locals())
            shell = code.InteractiveConsole(variables)
            shell.interact(banner="DEBUG REPL")
    else:
        premain(argparser)

if __name__ == "__main__":
    main()