You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

1808 lines
61 KiB

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import os
import getpass
import telnetlib
import re
import time
import keyboard
import random
import sys
import paho.mqtt.client as mqtt
HOST = "telnet.goldenunicorn.net"
choice = int(sys.argv[1])
print("choice:"+sys.argv[1])
usr_1 = ""
pwrd_1 = ""
char_sel_1 = 4
weapon_1 = ""
spell_1 = ""
usr_2 = ""
pwrd_2 = ""
char_sel_2 = 4
weapon_2 = ""
spell_2 = ""
usr_3 = ""
pwrd_3 = ""
char_sel_3 = 2
weapon_3 = ""
spell_3 = ""
usr_4 = ""
pwrd_4 = ""
char_sel_4 = 1
weapon_4 = ""
spell_4 = ""
usr_5 = ""
pwrd_5 = ""
char_sel_5 = 4
weapon_5 = ""
spell_5 = ""
usr_6 = ""
pwrd_6 = ""
char_sel_6 = 4
weapon_6 = ""
spell_6 = ""
usr_7 = ""
pwrd_7 = ""
char_sel_7 = 4
weapon_7 = ""
spell_7 = ""
usr_8 = ""
pwrd_8 = ""
char_sel_8 = 4
weapon_8 = ""
spell_8 = ""
if choice == 1:
usr_1 = "epilectrik"
pwrd_1 = "gupass"
char_sel_1 = 4
weapon_1 = "Nuclear-Decay"
spell_1 = "dispell"
usr_2 = "im bait"
pwrd_2 = "gupass"
char_sel_2 = 4
weapon_2 = "Nuclear-Decay"
spell_2 = "dispell"
usr_3 = "doctor"
pwrd_3 = "gupass"
char_sel_3 = 2
weapon_3 = "Nuclear-Decay"
spell_3 = "cure poison"
usr_4 = "robin-hood"
pwrd_4 = "gupass"
char_sel_4 = 1
weapon_4 = "Nuclear-Decay"
spell_4 = "invisibility"
usr_5 = "assassin"
pwrd_5 = "gupass"
char_sel_5 = 4
weapon_5 = "Nuclear-Decay"
spell_5 = "dispell"
usr_6 = "mercenary"
pwrd_6 = "gupass"
char_sel_6 = 4
weapon_6 = "Nuclear-Decay"
spell_6 = "dispell"
usr_7 = "mutant-warrior-1"
pwrd_7 = "gupass"
char_sel_7 = 4
weapon_7 = "nuclear-decay"
spell_7 = "dispell"
usr_8 = "mutant-warrior-2"
pwrd_8 = "gupass"
char_sel_8 = 4
weapon_8 = "nuclear-decay"
spell_8 = "dispell"
if choice == 2:
usr_1 = "Mtron"
pwrd_1 = "gupass"
char_sel_1 = 4
weapon_1 = "Nuclear-Decay"
usr_2 = "IonJunkies-Merc"
pwrd_2 = "gupass"
char_sel_2 = 4
weapon_2 = "Nuclear-Decay"
#this is a thing that i wrote
#static lists
convert_list = ["Ion-Pack","Ion-Decay","Cheese","Nuclear-thong","Skull","Bottle-Cap","Cigarette-Butt","Knife","Gas-Grenade","Leather-Vest","Buckler","Bola","Bug-Plate",
"Light-Spear","Silver-Potion","Bastard-Sword","Invisible-Knife","Great-Club","Spear","Blizzard-Staff","Devil_Key","Grey-Dagger","Bone","Axe","BlackJack",
"Golden-Key","Crystal-Key","Trident","Ice-Knife","Iron-Sickle","Gold-Spear","Fang-Dagger","Hound-Fang","Pink-Potion","Small-Dagger","Mage-Stick","Purple-Potion",
"Tree-Branch","Poker","Bronze Knife","Small-Club","Wonderous-Sword","Spell-Potion","Long-Sword","Ion-Gauntlet","Sling-Sword","Small-Spear","Iron-Mace","Iron-Boots",
"Tree-Stump","Saphire","Flame-Sword","Rock-Club","Lava-Dagger","Bloody-Arm","Golden-Needle","Ion-Booster","Devil-Key","Chain-Mail","Weak-Cloth","Splint-Mail","Rags",
"Bug-Skin","Troll-Sword","Axe","Plate-Mail","Common-Hide","Kelp-Mail","Green-Vial","Broken-Armour","Broken-Weapon"]
farm_sell_list = ["Gold-Chunck","Nuclear-Rock","Nuclear-Waste"]
farm_stock_list = ["Nuclear-Decay","Eazy-Armor","Hell-Blade"]
friend_list = ["Epilectrik","ImBait","Mtron","Im","IonJunkies-Merc","Robin-Hood","Doctor","Assassin","Mercenary","Mutant-warrior-1","Mutant-warrior-2"]
help_list = ["$ - Key listener on/off",
"8 - North",
"2 - South",
"6 - East",
"4 - West",
"5 - Look direction",
"c - Combat",
"w - Wield weapon",
"a - Auto combat on/off",
"f - Auto farm on/off",
"i - Auto Ion on/off",
"t - time travel",
"d - drop item",
"k - keyboard input",
"v - status",
"m - meander"
]
opposite_dir = {
"north":"south",
"south":"north",
"east":"west",
"west":"east",
}
#Heater popup window
class mutant(QWidget):
command_str = pyqtSignal(str)
mqtt_str = pyqtSignal(str)
mqtt_str_quiet = pyqtSignal(str,str)
def __init__(self,user,password,char_sel,weapon,spell):
QWidget.__init__(self)
#file related
self.path=user
#dynamic lists
self.local_items = []
self.local_monsters = []
self.direction_list = []
self.sell_list = []
self.stock_list = []
self.bank_list = []
#modes
self.heal = False
self.wander = False
self.bait = False
self.hunt = False
self.auto_combat = True
self.auto_ion = True
self.auto_farm = False
self.key_detect = False
#states
self.time_steps = 0
self.in_play = False
self.in_combat = False
self.hits = 0
self.lock_key="["
self.area_indexed = True
self.stat_parsed = True
self.previous_dir = ""
self.selected_path = 0
self.path_step = 0
self.location = [0,0]
self.weapon = "Nuclear-Decay"
self.spell = spell
self.watchdog = 0
#value tracking
self.riblets = 0
self.ions = 0
self.hp = 0
self.exp = 0
self.clss = "Thief"
self.level = 0
self.riblet_thresh = 200000
self.farm_year=2000
self.year_limit=2500
self.no_action_cnt = 0
self.na_thresh = 150
self.status = ""
self.area = ""
self.console_lines = 0
#account
self.user = user
self.password = password
self.char_sel = char_sel
self.logged_in = False
#timers
#healing
self.heal_timer = QTimer()
self.heal_timer.setInterval(1000)
self.heal_timer.timeout.connect(self.heal_trig)
self.heal_timer.start()
#wielding
self.wield_timer = QTimer()
self.wield_timer.setInterval(200)
self.wield_timer.timeout.connect(self.wield_trig)
self.wield_timer.start()
#wander
self.wander_timer = QTimer()
self.wander_timer.setInterval(500)
self.wander_timer.timeout.connect(self.wander_trig)
self.wander_timer.start()
#stat
self.stat_timer = QTimer()
self.stat_timer.setInterval(30000)
self.stat_timer.timeout.connect(self.stat_trig)
self.stat_timer.start()
#path
self.path_timer = QTimer()
self.path_timer.setInterval(100)
self.path_timer.timeout.connect(self.path_trig)
self.path_timer.start()
#watchdog
self.watchdog_timer = QTimer()
self.watchdog_timer.setInterval(30000)
self.watchdog_timer.timeout.connect(self.watchdog_t)
self.watchdog_timer.start()
#layout stuff
self.layout = QVBoxLayout()
# Add console
self.console = QTextEdit()
self.console.setTextColor(QColor(255, 255, 255))
self.console.setStyleSheet("QTextEdit { color: white; background-color: rgb(0, 0, 0); font-size: 18px; }")
self.console.clear()
self.console.append("test")
self.layout.addWidget(self.console)
#Add buttons
self.button_group()
# Add text input
self.formGroupBox = QFormLayout()
self.text_input = QLineEdit()
self.text_button = QPushButton("Send")
self.text_button.clicked.connect(self.send_str)
self.formGroupBox.addRow(self.text_button,self.text_input)
self.layout.addLayout(self.formGroupBox)
#stat group
self.createStatGroup()
self.layout.addLayout(self.stat_layout)
#mode group
self.createModeGroup()
self.layout.addLayout(self.mode_layout)
#settings group
self.createSettingsGroup()
self.layout.addLayout(self.settingsGroupBox)
self.weapon_input.setText(weapon)
self.setLayout(self.layout)
self.load_bank_paths()
self.init_telnet()
def init_telnet(self):
#init telnet thread
self.tn_obj = telnet_thread()
self.tn_thread = QThread()
self.tn_obj.moveToThread(self.tn_thread)
#Connect signals
self.tn_thread.started.connect(self.tn_obj.telnet_listen)
self.tn_obj.received.connect(self.execute_loop)
self.command_str.connect(self.tn_obj.tn_write)
self.tn_obj.disconnected.connect(self.reconnect)
#start thread
self.tn_thread.start()
def reconnect(self):
self.player_init()
print("obj restarting")
#create buttons
def button_group(self):
hbox1 = QHBoxLayout()
b_grid = QGridLayout()
button_w = 50
north_button = QPushButton("North")
south_button = QPushButton("South")
east_button = QPushButton("East")
west_button = QPushButton("West")
heal_button = QPushButton("Heal")
combat_button = QPushButton("Combat")
path_button = QPushButton("Path")
look_button = QPushButton("Look")
stat_button = QPushButton("Stat")
b_grid.addWidget(north_button,0,1)
b_grid.addWidget(south_button,2,1)
b_grid.addWidget(east_button,1,2)
b_grid.addWidget(west_button,1,0)
b_grid.addWidget(heal_button,0,0)
b_grid.addWidget(combat_button,0,2)
b_grid.addWidget(path_button,2,0)
b_grid.addWidget(look_button,1,1)
b_grid.addWidget(stat_button,2,2)
hbox1.addItem(QSpacerItem(150, 0, QSizePolicy.Minimum))
hbox1.addLayout(b_grid)
hbox1.addItem(QSpacerItem(150, 0, QSizePolicy.Minimum))
north_button.clicked.connect(self.n_btn)
south_button.clicked.connect(self.s_btn)
east_button.clicked.connect(self.e_btn)
west_button.clicked.connect(self.w_btn)
heal_button.clicked.connect(self.h_btn)
combat_button.clicked.connect(self.c_btn)
path_button.clicked.connect(self.p_btn)
look_button.clicked.connect(self.l_btn)
stat_button.clicked.connect(self.st_btn)
self.layout.addLayout(hbox1)
#Creates the form groupbox
def createModeGroup(self):
self.mode_layout = QVBoxLayout()
hbox1 = QHBoxLayout()
hbox2 = QHBoxLayout()
self.ac_check = QCheckBox("Auto Combat")
self.ac_check.setChecked(True)
self.af_check = QCheckBox("Auto Farm")
self.ai_check = QCheckBox("Auto Ion")
self.ai_check.setChecked(True)
self.me_check = QCheckBox("Meander")
self.ba_check = QCheckBox("Bait")
self.hu_check = QCheckBox("Hunt")
self.ac_check.stateChanged.connect(self.ac_checked)
self.af_check.stateChanged.connect(self.af_checked)
self.ai_check.stateChanged.connect(self.ai_checked)
self.me_check.stateChanged.connect(self.me_checked)
self.ba_check.stateChanged.connect(self.ba_checked)
self.hu_check.stateChanged.connect(self.hu_checked)
hbox1.addWidget(self.ac_check)
hbox1.addWidget(self.af_check)
hbox1.addWidget(self.ba_check)
hbox2.addWidget(self.ai_check)
hbox2.addWidget(self.me_check)
hbox2.addWidget(self.hu_check)
self.mode_layout.addLayout(hbox1)
self.mode_layout.addLayout(hbox2)
#stat labels
def createStatGroup(self):
self.stat_layout = QVBoxLayout()
hbox1 = QHBoxLayout()
hbox2 = QHBoxLayout()
userLabel = QLabel("User: ")
self.userLabel = QLabel("None")
expLabel = QLabel("Exp: ")
self.expLabel = QLabel("None")
levelLabel = QLabel("Level: ")
self.levelLabel = QLabel("None")
yearLabel = QLabel("Year: ")
self.yearLabel = QLabel("None")
locationLabel = QLabel("Loc: ")
self.locationLabel = QLabel("None")
hpLabel = QLabel("HP: ")
self.hpLabel = QLabel("None")
ribletLabel = QLabel("Riblets: ")
self.ribletLabel = QLabel("None")
ionLabel = QLabel("Ions: ")
self.ionLabel = QLabel("None")
hbox1.addWidget(userLabel)
hbox1.addWidget(self.userLabel)
hbox1.addWidget(expLabel)
hbox1.addWidget(self.expLabel)
hbox1.addWidget(levelLabel)
hbox1.addWidget(self.levelLabel)
hbox1.addWidget(yearLabel)
hbox1.addWidget(self.yearLabel)
hbox2.addWidget(locationLabel)
hbox2.addWidget(self.locationLabel)
hbox2.addWidget(hpLabel)
hbox2.addWidget(self.hpLabel)
hbox2.addWidget(ribletLabel)
hbox2.addWidget(self.ribletLabel)
hbox2.addWidget(ionLabel)
hbox2.addWidget(self.ionLabel)
self.stat_layout.addLayout(hbox1)
self.stat_layout.addLayout(hbox2)
#Text inputs
def createSettingsGroup(self):
self.settingsGroupBox = QFormLayout()
self.weapon_input = QLineEdit("Nuclear-Decay")
self.na_input = QLineEdit("150")
self.yl_input = QLineEdit("2500")
self.path_input = QLineEdit("0")
self.settingsGroupBox.addRow(QLabel("Weapon:"),self.weapon_input)
self.settingsGroupBox.addRow(QLabel("No Action:"),self.na_input)
self.settingsGroupBox.addRow(QLabel("Year Limit:"),self.yl_input)
self.settingsGroupBox.addRow(QLabel("Path:"),self.path_input)
#buttons
def n_btn(self):
self.command_str.emit("north\r\n")
def s_btn(self):
self.command_str.emit("south\r\n")
def e_btn(self):
self.command_str.emit("east\r\n")
def w_btn(self):
self.command_str.emit("west\r\n")
def h_btn(self):
self.heal = True
def c_btn(self):
self.combat_start()
def p_btn(self):
self.path_step=1
def l_btn(self):
self.command_str.emit("look\r\n")
def st_btn(self):
self.command_str.emit("stat\r\n")
#load bank file
def load_bank_paths(self):
file = "./"+self.path+"/banks.txt"
if (os.path.exists(self.path) == False):
os.makedirs(self.path)
f = open(file, "x")
f.write("done,done\r\n")
f.seek(0)
print("creating "+file)
else:
print("File Exists")
with open(file, 'r') as script:
while True:
in_str = script.readline().strip()
if in_str != "":
self.bank_list.append(in_str.split(","))
# end of file is reached
if not in_str:
break
#Button send text
def send_str(self):
self.command_str.emit(self.text_input.text()+"\r\n")
#auto combat checked
def ac_checked(self):
self.auto_combat = self.ac_check.isChecked()
print("Auto Combat: "+str(self.auto_combat))
#auto farm checked
def af_checked(self):
self.auto_farm = self.af_check.isChecked()
print("Auto farm: "+str(self.auto_farm))
#auto ion checked
def ai_checked(self):
self.auto_ion = self.ai_check.isChecked()
print("Auto ion: "+str(self.auto_ion))
#meander checked
def me_checked(self):
self.wander = self.me_check.isChecked()
print("Wander: "+str(self.wander))
#meander checked
def ba_checked(self):
self.bait = self.ba_check.isChecked()
print("Bait: "+str(self.bait))
#meander checked
def hu_checked(self):
self.hunt = self.hu_check.isChecked()
print("Hunt: "+str(self.hunt))
#heal timer
def heal_trig(self):
if self.heal and self.logged_in and self.in_play:
self.command_str.emit("heal\r\n")
#self.mqtt_str_quiet.emit(self.user," is healing." )
#wield timer
def wield_trig(self):
if self.in_combat and self.logged_in and self.in_play:
self.command_str.emit("wie "+self.weapon+"\r\n")
#wander timer
def wander_trig(self):
if self.wander and self.logged_in and self.in_play and not self.in_combat and self.path_step == 0:
self.area_indexed = False
self.local_monsters = []
self.local_items = []
print("wander triggered")
print("no action: " + str(self.no_action_cnt))
#increment no action counter
self.no_action_cnt = self.no_action_cnt + 1
if len(self.direction_list) == 0:
self.command_str.emit("look\r\n")
#pick randomly
if len(self.direction_list) > 0:
if len(self.direction_list) > 1:
try:
self.direction_list.remove(self.previous_dir)
except:
pass
#print(self.direction_list)
dir_choice = random.choice(self.direction_list)
try:
if dir_choice == "north":
self.location[1] = self.location[1] + 1
if dir_choice == "south":
self.location[1] = self.location[1] - 1
if dir_choice == "east":
self.location[0] = self.location[0] + 1
if dir_choice == "west":
self.location[0] = self.location[0] - 1
except:
pass
self.command_str.emit(dir_choice+"\r\n")
self.direction_list = []
self.previous_dir = opposite_dir[dir_choice]
#stat timer
def stat_trig(self):
if self.logged_in and self.in_play and not self.in_combat and self.path_step == 0:
self.command_str.emit("stat\r\n")
self.command_str.emit("look\r\n")
#path timer
def path_trig(self):
if self.logged_in and self.in_play and not self.in_combat:
self.path_process()
#search a list
def search(self, list, platform):
for i in range(len(list)):
if list[i] == platform:
return True
return False
#Reup Ions
def convert_items(self):
for item_l in self.local_items:
for item in convert_list:
if item_l == item:
self.command_str.emit("get "+item+"\r\n")
self.command_str.emit("con "+item+"\r\n")
self.mqtt_str_quiet.emit(self.user," converted " + item )
try:
self.local_items.remove(item_l)
except:
pass
#Farms valuable stuff
def farm_sell_items(self):
for item_l in self.local_items:
for item in farm_sell_list:
if item_l == item:
self.command_str.emit("get "+item+"\r\n")
self.local_items.remove(item_l)
self.sell_list.append(item_l)
self.no_action_cnt = 0
#Farms valuable stuff
def farm_stock_items(self):
for item_l in self.local_items:
for item in farm_stock_list:
if item_l == item:
self.command_str.emit("get "+item+"\r\n")
self.local_items.remove(item_l)
self.stock_list.append(item_l)
self.no_action_cnt = 0
#Sell items
def sell_items(self):
print(self.sell_list)
while len(self.sell_list) > 0:
item_l=self.sell_list[0]
self.sell_list.pop(0)
self.command_str.emit("sell "+item_l+"\r\n")
time.sleep(.05)
#Stock
def stock_items(self):
print(self.stock_list)
while len(self.stock_list) > 0:
item_l=self.stock_list[0]
self.stock_list.pop(0)
self.command_str.emit("stock "+item_l+"\r\n")
time.sleep(.05)
#Drop monster baits
def drop_baits(self):
while self.stock_list.count("Monster-Bait") > 1:
self.command_str.emit("drop monster-bait\r\n")
self.stock_list.remove("Monster-Bait")
#Remove friends from monster list
def remove_friends(self):
for friend in friend_list:
try:
self.local_monsters.remove(friend)
except:
pass
#Flushes keyboard
def flush_input(self):
try:
import msvcrt
while msvcrt.kbhit():
msvcrt.getch()
except ImportError:
import sys, termios
termios.tcflush(sys.stdin, termios.TCIOFLUSH)
#Decode incoming information
def decode_line(self,line):
result = ""
if line.decode('cp1252') != "":
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
result = ansi_escape.sub('', line.decode('cp1252').strip('\n'))
self.console.append(result)
return result
#initiate combat
def combat_start(self):
try:
self.command_str.emit("combat " + self.local_monsters[0]+"\r\n")
self.mqtt_str_quiet.emit(self.user," is attacking " + self.local_monsters[0] )
except:
pass
self.in_combat = True
self.heal = True
self.wield_trig()
self.path_step = 0
self.no_action_cnt = 0
#process wander
def wander_process(self, result):
#area clear
if result.find("north - area continues.") != -1 or result.find("north - open gate.") != -1:
self.direction_list.append("north")
if result.find("south - area continues.") != -1 or result.find("south - open gate.") != -1:
self.direction_list.append("south")
if result.find("east - area continues.") != -1 or result.find("east - open gate.") != -1:
self.direction_list.append("east")
if result.find("west - area continues.") != -1 or result.find("west - open gate.") != -1:
self.direction_list.append("west")
#are there monsters
if result.find("You see shadows to the") != -1 and not self.hunt:
try:
if result.find("north") != -1:
self.direction_list.remove("north")
if result.find("south") != -1:
self.direction_list.remove("south")
if result.find("east") != -1:
self.direction_list.remove("east")
if result.find("west") != -1:
self.direction_list.remove("west")
except:
pass
#process combat per loop
def combat_process(self, result):
if result.find("You suffer") != -1:
self.hits = self.hits + 1
if self.hits == 2:
self.command_str.emit("heal\r\n")
self.command_str.emit("heal\r\n")
self.hits = 0
if result.find("have slain") != -1 or result.find("has just left") != -1 or result.find("isn't around here!") != -1 or result.find("You're not ready") != -1:
try:
self.local_monsters.pop(0)
except:
pass
if len(self.local_monsters) > 0:
self.command_str.emit("combat " + self.local_monsters[0]+"\r\n")
else:
#print("Area cleared")
self.in_combat = False
#time travel
def time_travel(self):
self.local_items = []
self.location = [0,0]
self.farm_year = self.farm_year + 100
if self.farm_year > self.year_limit:
self.farm_year = 2000
self.command_str.emit("tra "+str(self.farm_year)+"\r\n")
self.drop_baits()
if self.bait and not self.stock_list.count("Monster-Bait"):
self.command_str.emit("get Monster-Bait\r\n")
self.stock_list.append("Monster-Bait")
self.command_str.emit("look\r\n")
#process path
def path_process(self):
path_str = self.bank_list[self.selected_path][self.path_step]
if path_str != "done":
if path_str[0] == "!":
self.script_function(path_str.strip("!").upper())
else:
self.command_str.emit(path_str+"\r\n")
self.path_step = self.path_step + 1
self.no_action_cnt = 0
else:
self.path_step = 0
#handle functions in path script
def script_function(self,function):
if function == "DEPOSIT":
self.command_str.emit("deposit "+str(self.riblets)+"\r\n")
self.mqtt_str_quiet.emit(self.user," deposited "+str(self.riblets)+" riblets" )
self.riblets = 0
if function == "STOCK":
self.stock_items()
if function == "SELL":
self.sell_items()
if function == "RETURN":
self.path_step = -1
self.command_str.emit("tra "+str(self.farm_year)+"\r\n")
new_path = self.selected_path + 1
if new_path == len(self.bank_list):
new_path = 0
self.path_input.setText(str(new_path))
#process stats
def parse_stat(self, result):
if self.stat_parsed == False:
self.sell_list = []
self.stock_list = []
self.status += result
if result.find(">") != -1:
self.stat_parsed = True
#Retally items, convert extras
if self.stat_parsed and self.status != "":
self.watchdog = 0
for item_l in farm_sell_list:
x = self.status.count(item_l)
for i in range(x):
if i < 3:
self.sell_list.append(item_l)
else:
self.command_str.emit("con "+item_l+"\r\n")
for item_l in farm_stock_list:
x = self.status.count(item_l)
for i in range(x):
if i < 3:
self.stock_list.append(item_l)
else:
self.command_str.emit("con "+item_l+"\r\n")
#HP
if self.status.find("Hit Points :") != -1:
start_index = self.status.index('Hit Points : ') + 15
hp_str = self.status[start_index:]
try:
end_index = hp_str.index('/')
except:
pass
hp_str = hp_str[:end_index]
try:
self.hp = int(hp_str)
except:
pass
#exp
if self.status.find("Exp. Points :") != -1:
start_index = self.status.index('Exp. Points : ') + 15
exp_str = self.status[start_index:]
try:
end_index = exp_str.index('Level')
except:
pass
exp_str = exp_str[:end_index]
try:
self.exp = int(exp_str)
except:
pass
#scrape level
if self.status.find("Level: ") != -1:
start_index = self.status.index('Level: ') + 7
level_str = self.status[start_index:]
try:
end_index = level_str.index('Riblets')
except:
pass
level_str = level_str[:end_index]
try:
self.level = int(level_str)
except:
pass
#scrape riblets
if self.status.find("Riblets :") != -1:
start_index = self.status.index('Riblets : ') + 16
riblets_str = self.status[start_index:]
try:
end_index = riblets_str.index('Ions')
except:
pass
riblets_str = riblets_str[:end_index]
#print("Riblets:" + riblets_str)
try:
self.riblets = int(riblets_str)
except:
pass
#scrape ions
if self.status.find("Ions : ") != -1:
start_index = self.status.index('Ions : ') + 16
ions_str = self.status[start_index:]
try:
end_index = riblets_str.index('Wearing')
except:
pass
ions_str = ions_str[:end_index]
#print("Riblets:" + riblets_str)
try:
self.ions = int(ions_str)
except:
pass
#scrape year
if self.status.find("Year A.D. :") != -1:
start_index = self.status.index('Year A.D. : ') + 17
year_str = self.status[start_index:]
try:
end_index = 4
except:
pass
year_str = year_str[:end_index]
#print("Year:" + year_str)
try:
self.farm_year = int(year_str)
except:
pass
self.status = ""
#index area
def index_area(self,result):
if self.area_indexed == False:
self.area += result
if result.find(">") != -1:
self.area_indexed = True
if self.area_indexed and self.area != "":
if self.area.find("On the ground lies:") != -1:
start_index = self.area.index('On the ground lies:')
item_str = self.area[start_index:]
try:
end_index = item_str.index('***')
except:
try:
end_index = item_str.index('>')
except:
pass
item_str = item_str[:end_index]
item_str = item_str.replace("On the ground lies:","")
item_str = item_str.replace("0","")
item_str = item_str.replace("1","")
item_str = item_str.replace("2","")
item_str = item_str.replace("3","")
item_str = item_str.replace("4","")
item_str = item_str.replace("5","")
item_str = item_str.replace("6","")
item_str = item_str.replace("7","")
item_str = item_str.replace("8","")
item_str = item_str.replace("9","")
item_str = item_str.replace("(","")
item_str = item_str.replace(")","")
item_str = item_str.replace("A ","")
item_str = item_str.replace("An ","")
item_str = item_str.replace(" ","")
item_str = item_str.replace(".","")
item_str = item_str.replace("\r\n","")
item_str = item_str.replace("***","")
self.local_items = list(item_str.split(","))
#print(self.local_items)
if self.area.find("is here") != -1 or self.area.find("are here") != -1:
try:
end_index = self.area.index('here')
monster_str = self.area[:end_index]
start_index = monster_str.rindex('***')
monster_str = monster_str[start_index:]
monster_str = monster_str.replace("\r\n","")
monster_str = monster_str.replace(" and ","")
monster_str = monster_str.replace(" are ","")
monster_str = monster_str.replace(" is ","")
monster_str = monster_str.replace(" ","")
monster_str = monster_str.replace(".","")
monster_str = monster_str.replace("***","")
self.local_monsters = list(monster_str.split(","))
self.remove_friends()
#print(self.local_monsters)
except:
pass
self.area = ""
#drop
def exit_game(self):
self.in_combat=False
self.heal = False
self.wander = False
self.auto_farm = False
self.auto_combat = False
self.in_play = False
self.hunt = False
self.ac_check.setChecked(False)
self.af_check.setChecked(False)
self.ai_check.setChecked(False)
self.me_check.setChecked(False)
self.ba_check.setChecked(False)
self.hu_check.setChecked(False)
#Player starting condition
def player_init(self):
self.in_combat=False
self.heal = False
self.wander = False
self.auto_farm = False
self.auto_combat = True
self.auto_ion = True
self.in_play = False
self.hunt = False
self.logged_in = False
self.ac_check.setChecked(True)
self.af_check.setChecked(False)
self.ai_check.setChecked(True)
self.me_check.setChecked(False)
self.ba_check.setChecked(False)
self.hu_check.setChecked(False)
#Resets connection with no activity
def watchdog_t(self):
if self.watchdog > 4:
self.player_init()
self.tn_obj.close_telnet()
self.watchdog = 0
else:
self.watchdog = self.watchdog + 1
#Main game loop
def mutants(self,result):
#update farm year text box
try:
self.userLabel.setText(self.user)
self.expLabel.setText(str(self.exp))
self.levelLabel.setText(str(self.level))
self.yearLabel.setText(str(self.farm_year))
self.locationLabel.setText(str(self.location))
self.hpLabel.setText(str(self.hp))
self.ribletLabel.setText(str(self.riblets))
self.ionLabel.setText(str(self.ions))
self.weapon = self.weapon_input.text()
self.na_thresh = int(self.na_input.text())
self.year_limit = int(self.yl_input.text())
self.selected_path = int(self.path_input.text())
except:
pass
#Nothing has happened in a while, time jump
if self.no_action_cnt > self.na_thresh:
self.time_travel()
self.no_action_cnt = 0
#New area, take a look
#Detect in play
if result.find("Prepare to walk a thousand years!") != -1:
self.in_play = True
self.command_str.emit("blurb\r\n")
self.command_str.emit("deaf\r\n")
self.command_str.emit("memorize "+self.spell+"\r\n")
print("Character in play..")
#New area, set index, get location
if result.find("Compass:") != -1:
res_filter = result.replace("Compass:","")
res_filter = res_filter.replace("Compass:","")
res_filter = res_filter.replace("N","")
res_filter = res_filter.replace("E","")
res_filter = res_filter.replace(":",",")
res_filter = res_filter.replace("(","")
res_filter = res_filter.replace(")","")
res_filter = res_filter.replace(" ","")
try:
self.location = list(map(int, res_filter.split(",")))
except:
print('location failed')
#print(self.location)
self.area_indexed = False
#drop baits
if self.location == [0,0]:
self.drop_baits()
#too many baits
if self.stock_list.count("Monster-Bait") > 3:
self.command_str.emit("drop Monster-Bait\r\n")
self.stock_list.remove("Monster-Bait")
#print(self.stock_list)
#too many nuclear decays
if self.stock_list.count("Nuclear-Decay") > 3:
self.command_str.emit("con nuclear-decay\r\n")
self.stock_list.remove("Nuclear-Decay")
#print(self.stock_list)
#parse status
self.parse_stat(result)
#index area
self.index_area(result)
#deposit riblets
if self.riblets > self.riblet_thresh and self.path_step == 0 and self.wander:
self.path_step = 1
#auto farm if sold items
if len(self.sell_list) == 0 and self.wander:
self.auto_farm = True
#process wander
if self.wander and not self.in_combat and self.path_step == 0:
self.wander_process(result)
#process combat
if self.in_combat:
self.combat_process(result)
#scrapers
if result.find("(N)onstop, (Q)uit, or (C)ontinue?") != -1:
self.command_str.emit("C")
#ion starvation
if result.find("You're starving for IONS!") != -1:
self.command_str.emit("con gold-chunck\r\n")
self.auto_combat = True
self.heal = True
#too heavy
if self.wander and result.find("The weight of all your items forces you to the ground.") != -1:
self.wander = False
self.command_str.emit("X\r\n")
#dropped your weapon!
if self.auto_farm and result.find("The Nuclear-Decay fell out of your sack!") != -1:
self.time_steps = 0
self.command_str.emit("con gold-chunck\r\n")
self.command_str.emit("get nuclear-decay\r\n")
#I can't remember why I did this
if self.auto_farm and result.find("You're not carrying a gold-chunck.") != -1:
self.auto_farm = False
#Dropped the bait, pick it back up
if result.find("The Monster-Bait fell out of your sack!") != -1:
self.time_steps = 0
self.command_str.emit("con gold-chunck\r\n")
self.command_str.emit("get monster-bait\r\n")
#Detect bait mode, add or remove from stock list
if self.bait:
if not farm_stock_list.count("Monster-Bait"):
farm_stock_list.append("Monster-Bait")
else:
try:
farm_stock_list.remove("Monster-Bait")
except:
pass
#Exit game if..
if self.in_combat and result.find("You're not carrying a "+self.weapon.lower()) != -1:
self.command_str.emit("kick\r\n")
#self.exit_game()
#Lighten
if self.wander and (result.find("It's too dark to see anything!") != -1 and self.path_step == 0):
self.command_str.emit("cast\r\n")
#GTFO
#if result.find("You're blocked!") != -1 or len(self.local_monsters) > 4:
# self.heal = True
# local_monsters = []
# self.command_str.emit("tra "+str(self.farm_year)+"\r\n")
# self.in_combat = False
#Sell the loot
if (result.find("City Trading Centre") != -1 or result.find("Satan Inc. Trade Centre") != -1) and self.path_step == 0:
if len(self.sell_list) > 0:
self.sell_items()
#Parse character status
if result.find("stat") != -1:
self.stat_parsed = False
#Trigger stop healing
if result.find("Nothing happens!") != -1 or result.find("You don't have enough ions to heal!") != -1:
self.heal = False
#Turn on healing
if result.find("You suffer") != -1 or result.find("You are poisoned!") != -1:
self.heal = True
#Monster list related
if (result.find("yells: Gimmie") != -1 or
result.find("just arrived from") != -1 or
result.find("has hit") != -1 or
result.find("body is glowing") != -1 or
result.find("Get away from me") != -1 or
result.find("just appeared through a time portal!") != -1):
m = result.index(' ')
monster = result[:m]
if not self.search(self.local_monsters, monster):
self.local_monsters.append(monster)
self.remove_friends()
#print(self.local_monsters)
#Start Combat
if len(self.local_monsters) > 0 and self.auto_combat and not self.in_combat:
self.combat_start()
#Monster took off, remove from list
if result.find("has just left") != -1:
try:
end_index = result.index(' has')
mon_str = result[:end_index]
mon_str = mon_str.replace(" ","")
self.local_monsters.remove(mon_str)
except:
pass
#Monster died, remove from list
if result.find("is crumbling to dust") != -1:
try:
end_index = result.index(' is')
mon_str = result[:end_index]
mon_str = mon_str.replace(" ","")
self.local_monsters.remove(mon_str)
except:
pass
#Someone picked something up, remove from item list
if result.find("picked up the") != -1:
try:
start_index = result.index('the') + 4
item_str = result[start_index:]
end_index = item_str.index('.')
item_str = item_str[:end_index]
item_str = item_str.replace(" ","")
self.local_items.remove(item_str)
except:
pass
#Dead person dropping stuff, add to local list
if result.find("is falling from") != -1:
try:
start_index = result.index('A')
item_str = result[start_index:]
end_index = item_str.index('is')
item_str = item_str[:end_index]
item_str = item_str.replace(" ","")
item_str = item_str.replace("is","")
item_str = item_str.replace("An","")
item_str = item_str.replace("A","")
self.local_items.append(item_str)
except:
print("Monster item drop error")
print(result)
#print(self.local_items)
#You died, do some stuff
if result.find("Select (Bury, 1-5, ?)") != -1:
self.mqtt_str.emit(self.user+" has died")
self.mqtt_str_quiet.emit(self.user," has died")
print("MQTT signal emitted")
self.exit_game()
#farm items
if len(self.local_items) > 0 and not self.in_combat and not self.path_step:
farm_zero = True
if self.location == [0,0]:
farm_zero = False
if not self.wander:
farm_zero = True
if self.auto_farm and farm_zero:
self.farm_sell_items()
self.farm_stock_items()
if self.auto_ion:
self.convert_items()
#print("convert")
def process_keys(self, key):
#keyboard related - this part sucks
if key==ord(self.lock_key):
if self.key_detect:
self.key_detect = False
print("Key detect off")
else:
self.key_detect = True
print("Key detect on")
if self.key_detect:
if key==ord("?"):
for help in help_list:
print(help)
#directions
if key==ord("8"):
self.local_monsters = []
self.local_items = []
self.command_str.emit("north\r\n")
if key==ord("2"):
self.local_monsters = []
self.local_items = []
self.command_str.emit("south\r\n")
if key==ord("4"):
self.local_monsters = []
self.local_items = []
self.command_str.emit("west\r\n")
if key==ord("6"):
self.local_monsters = []
self.local_items = []
self.command_str.emit("east\r\n")
#functions
if key==ord("a"):
if self.auto_combat:
self.auto_combat = False
print("Auto combat off")
else:
self.auto_combat = True
print("Auto combat on")
#Auto Ion
if key==ord("i"):
if self.auto_ion:
self.auto_ion = False
print("Auto ion off")
else:
self.auto_ion = True
print("Auto ion on")
#Auto farm
if key==ord("f"):
if self.auto_farm:
self.auto_farm = False
print("Auto farm off")
else:
self.auto_farm = True
print("Auto farm on")
#Year limit
if key==ord("y"):
self.flush_input()
st = input("Year limit: ")
self.year_limit = int(st)
#No action threshhold
if key==ord("n"):
self.flush_input()
st = input("No action: ")
self.na_thresh = int(st)
#Start combat
if key==ord("c"):
if len(self.local_monsters) > 0:
combat_start()
#look around
if key==ord("5"):
self.command_str.emit("look ")
#meander status
if key==ord("m"):
if self.wander:
self.wander = False
print("Meander off")
else:
self.wander = True
print("Meander on")
self.command_str.emit("look\r\n")
#heal
if key==ord("h"):
self.command_str.emit("heal\r\n")
self.heal = True
#look around
if key==ord("l"):
self.command_str.emit("look\r\n")
#stats
if key==ord("v"):
self.command_str.emit("stat\r\n")
#sell items
if key==ord("s"):
self.sell_items()
#store path select
if key==ord("p") and not self.in_combat:
self.flush_input()
st = input("Choose path input: ")
self.selected_path = int(st)
self.path_step = 1
self.command_str.emit("Starting path..\r\n")
self.flush_input()
if key==ord("K") and not self.in_combat:
print("working?")
st = input("Keyboard input: ")
self.command_str.emit(st+"\r\n")
self.flush_input()
#wield weapon
if key==ord("w"):
self.command_str.emit("wie "+self.weapon+"\r\n")
#drop item
if key==ord("d"):
self.flush_input()
#toss = keyboard.read_key()
st = input("drop item: ")
drop_item = "drop " + st
self.command_str.emit(drop_item+"\r\n")
#time travel
if key==ord("t") and not self.in_combat:
monster_list = []
self.flush_input()
#toss = keyboard.read_key()
st = input("year: ")
year = "travel " + st
self.command_str.emit(year+"\r\n")
if key==ord("x"):
pass
#login routine
def login_listener(self, result):
if result == "Otherwise type \"new\": ":
self.command_str.emit(self.user+"\r\n")
if result == "Enter your password: ":
self.command_str.emit(self.password+"\r\n")
if result == "(N)onstop, (Q)uit, or (C)ontinue?":
self.command_str.emit("Q")
if result == "Make your selection (G,T,F,M,S,? for help, or X to exit): ":
self.command_str.emit("G\r\n")
self.mqtt_str.emit(self.user+" is online")
self.mqtt_str_quiet.emit(self.user,"is online")
if result == "help, or X to exit): ":
self.command_str.emit("C\r\n")
if result == "Select (P,I,H,S,W,X,?): ":
self.command_str.emit("P\r\n")
if result == "Select (Bury, 1-5, ?) ":
self.command_str.emit(str(self.char_sel)+"\r\n")
#self.mutants()
self.logged_in = True
#doesnt work yet
def delete_line(self,line):
cursor = self.console.textCursor()
cursor.movePosition(QTextCursor.Start + line + 1)
cursor.movePosition(
QTextCursor.PreviousBlock,
QTextCursor.KeepAnchor, 1)
cursor.removeSelectedText()
self.console.setTextCursor(cursor)
#main game loop
def execute_loop(self, result):
self.console.append(result)
self.console_lines = self.console_lines +1
if self.logged_in == False:
self.login_listener(result)
else:
self.mutants(result)
if self.console_lines>5000:
self.console.clear()
self.console_lines = 0
self.console.moveCursor(QTextCursor.End)
class telnet_thread(QObject):
received = pyqtSignal(str)
disconnected = pyqtSignal()
#Init
def __init__(self):
QWidget.__init__(self)
#telnet lib
self.tn = telnetlib.Telnet()
self.open_telnet()
#Open connection
def open_telnet(self):
try:
self.tn.open(HOST,23)
print("telnet connected..")
except:
print("Connection attempt failed..")
#Close telnet
def close_telnet(self):
try:
self.tn.close()
print("closing telnet...")
except:
print("Telnet close failed...")
#Decode incoming information
def decode_line(self,line):
result = ""
if line.decode('cp1252') != "":
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
result = ansi_escape.sub('', line.decode('cp1252').strip('\n'))
return result
#Write to telnet object
def tn_write(self,send_str):
try:
self.tn.write(send_str.encode('ascii'))
except:
pass
#Listen perpetually
def telnet_listen(self):
print("listening..")
while True:
#data decode
QApplication.processEvents()
result = ""
line = None
try:
line = self.tn.read_until(b"\n",0) # Read one line
result = self.decode_line(line).strip("\r").strip("\n").strip("\b")
if result != "":
self.received.emit(result)
except:
try:
print("Reconnectiong...")
self.tn.close()
self.disconnected.emit()
self.open_telnet()
except:
print("Reconnect failed!")
class MainWindow(QMainWindow):
keyPressed = pyqtSignal(int)
def __init__(self):
super(MainWindow, self).__init__()
widget = QWidget(self)
self.layout = QVBoxLayout(widget)
self.setCentralWidget(widget)
self.setup_mqtt()
#Create tabs
self.tabs = QTabWidget()
self.tab1 = QWidget()
self.tab2 = QWidget()
self.tab3 = QWidget()
self.tab4 = QWidget()
#self.tabs.addTab(self.tab2,"Group 2")
#self.tabs.addTab(self.tab3,"Group 3")
#self.tabs.addTab(self.tab4,"Group 4")
#Create mutant objects
if usr_1 != "" and usr_2 != "":
mutbox1 = QHBoxLayout()
self.m1 = mutant(usr_1,pwrd_2,char_sel_1,weapon_1,spell_1)
self.m2 = mutant(usr_2,pwrd_2,char_sel_2,weapon_2,spell_2)
mutbox1.addWidget(self.m1)
mutbox1.addWidget(self.m2)
self.m1.mqtt_str.connect(self.send_mqtt)
self.m2.mqtt_str.connect(self.send_mqtt)
self.m1.mqtt_str_quiet.connect(self.send_mqtt_quiet)
self.m2.mqtt_str_quiet.connect(self.send_mqtt_quiet)
self.tabs.addTab(self.tab1,"Group 1")
self.tab1.setLayout(mutbox1)
#Create mutant objects
if usr_3 != "" and usr_4 != "":
mutbox2 = QHBoxLayout()
self.m3 = mutant(usr_3,pwrd_3,char_sel_3,weapon_3,spell_3)
self.m4 = mutant(usr_4,pwrd_4,char_sel_4,weapon_4,spell_4)
mutbox2.addWidget(self.m3)
mutbox2.addWidget(self.m4)
self.m3.mqtt_str.connect(self.send_mqtt)
self.m4.mqtt_str.connect(self.send_mqtt)
self.m3.mqtt_str_quiet.connect(self.send_mqtt_quiet)
self.m4.mqtt_str_quiet.connect(self.send_mqtt_quiet)
self.tabs.addTab(self.tab2,"Group 2")
self.tab2.setLayout(mutbox2)
#Create mutant objects
if usr_5 != "" and usr_6 != "":
mutbox3 = QHBoxLayout()
self.m5 = mutant(usr_5,pwrd_5,char_sel_5,weapon_5,spell_5)
self.m6 = mutant(usr_6,pwrd_6,char_sel_6,weapon_6,spell_6)
mutbox3.addWidget(self.m5)
mutbox3.addWidget(self.m6)
self.m5.mqtt_str.connect(self.send_mqtt)
self.m6.mqtt_str.connect(self.send_mqtt)
self.m5.mqtt_str_quiet.connect(self.send_mqtt_quiet)
self.m6.mqtt_str_quiet.connect(self.send_mqtt_quiet)
self.tabs.addTab(self.tab3,"Group 3")
self.tab3.setLayout(mutbox3)
#Create mutant objects
if usr_7 != "" and usr_8 != "":
mutbox4 = QHBoxLayout()
self.m7 = mutant(usr_7,pwrd_7,char_sel_7,weapon_7,spell_7)
self.m8 = mutant(usr_8,pwrd_8,char_sel_8,weapon_8,spell_8)
mutbox4.addWidget(self.m7)
mutbox4.addWidget(self.m8)
self.m7.mqtt_str.connect(self.send_mqtt)
self.m8.mqtt_str.connect(self.send_mqtt)
self.m7.mqtt_str_quiet.connect(self.send_mqtt_quiet)
self.m8.mqtt_str_quiet.connect(self.send_mqtt_quiet)
self.tabs.addTab(self.tab4,"Group 4")
self.tab4.setLayout(mutbox4)
#self.tab2.setLayout(self.h_2.layout)
#self.tab3.setLayout(self.h_1.layout)
#self.tab4.setLayout(self.h_2.layout)
self.layout.addWidget(self.tabs)
self.setLayout(self.layout)
#self.layout.addLayout(mutbox)
self.button_group()
self.createModeGroup()
self.show()
#Connect signals
#self.keyPressed.connect(self.m.process_keys)
# Add text input
self.formGroupBox = QFormLayout()
self.text_input = QLineEdit()
self.text_button = QPushButton("Send")
self.text_button.clicked.connect(self.send_str)
self.formGroupBox.addRow(self.text_button,self.text_input)
self.layout.addLayout(self.formGroupBox)
#Events like mouse movement and keyboard action that happen on the main form
def eventFilter(self, source, event):
#print(source)
if str(source).find("QWindow") != -1:
if event.type() == QEvent.KeyPress:
self.keyPressed.emit(event.key())
return QMainWindow.eventFilter(self, source, event)
#create buttons
def button_group(self):
hbox1 = QHBoxLayout()
hbox2 = QHBoxLayout()
b_grid = QGridLayout()
north_button = QPushButton("North")
south_button = QPushButton("South")
east_button = QPushButton("East")
west_button = QPushButton("West")
heal_button = QPushButton("Heal")
combat_button = QPushButton("Combat")
hbox2.addWidget(heal_button)
hbox2.addWidget(combat_button)
b_grid.addWidget(north_button,0,1)
b_grid.addWidget(south_button,2,1)
b_grid.addWidget(east_button,1,2)
b_grid.addWidget(west_button,1,0)
b_grid.addLayout(hbox2,1,1)
#b_grid.addWidget(heal_button,2,2)
#b_grid.addWidget(combat_button,2,0)
hbox1.addItem(QSpacerItem(350, 0, QSizePolicy.Minimum))
hbox1.addLayout(b_grid)
hbox1.addItem(QSpacerItem(350, 0, QSizePolicy.Minimum))
north_button.clicked.connect(self.n_btn)
south_button.clicked.connect(self.s_btn)
east_button.clicked.connect(self.e_btn)
west_button.clicked.connect(self.w_btn)
heal_button.clicked.connect(self.h_btn)
combat_button.clicked.connect(self.c_btn)
self.layout.addLayout(hbox1)
#buttons
def n_btn(self):
self.send_all("north\r\n")
def s_btn(self):
self.send_all("south\r\n")
def e_btn(self):
self.send_all("east\r\n")
def w_btn(self):
self.send_all("west\r\n")
def h_btn(self):
try:
self.m1.heal = True
self.m2.heal = True
except:
pass
try:
self.m3.heal = True
self.m4.heal = True
except:
pass
try:
self.m5.heal = True
self.m6.heal = True
except:
pass
try:
self.m7.heal = True
self.m8.heal = True
except:
pass
def c_btn(self):
try:
self.m1.combat_start()
self.m2.combat_start()
except:
pass
try:
self.m3.combat_start()
self.m4.combat_start()
except:
pass
try:
self.m5.combat_start()
self.m6.combat_start()
except:
pass
try:
self.m7.combat_start()
self.m8.combat_start()
except:
pass
#Button send text
def send_str(self):
self.send_all(self.text_input.text())
def send_all(self,out_str):
try:
self.m1.command_str.emit(out_str+"\r\n")
self.m2.command_str.emit(out_str+"\r\n")
except:
pass
try:
self.m3.command_str.emit(out_str+"\r\n")
self.m4.command_str.emit(out_str+"\r\n")
except:
pass
try:
self.m5.command_str.emit(out_str+"\r\n")
self.m6.command_str.emit(out_str+"\r\n")
except:
pass
try:
self.m7.command_str.emit(out_str+"\r\n")
self.m8.command_str.emit(self.text_input.text()+"\r\n")
except:
pass
#Creates the form groupbox
def createModeGroup(self):
self.mode_layout = QVBoxLayout()
hbox1 = QHBoxLayout()
hbox2 = QHBoxLayout()
self.mq_check = QCheckBox("MQTT")
self.mq_check.setChecked(True)
hbox1.addWidget(self.mq_check)
self.layout.addLayout(hbox1)
def setup_mqtt(self):
broker_address="192.168.86.27"
print("creating new instance")
self.client = mqtt.Client("P1") #create new instance
self.client.username_pw_set("homeassistant", "oes5gohng9gau1Quei2ohpixashi4Thidoon1shohGai2mae0ru2zaph2vooshai")
self.client.connect(broker_address)
#Send mqtt with talking
def send_mqtt(self,out_str):
self.setup_mqtt()
if self.mq_check.isChecked():
self.client.publish("mutants/talk", out_str)
#Send mqtt with talking
def send_mqtt_quiet(self,user,out_str):
self.setup_mqtt()
if self.mq_check.isChecked():
self.client.publish("mutants/stat/"+user, out_str)
if __name__ == "__main__":
App = QApplication(sys.argv)
QApplication.setQuitOnLastWindowClosed(True)
Root = MainWindow()
Root.show()
App.installEventFilter(Root)
sys.exit(App.exec())