def start(self, sender: SenderObj, duration, announce_interval, late_bid_threshold, late_bid_extension): if not self.items: return "Could not find any items to start auction." self.is_started = True self.auction_start_time = int(time.time()) self.auctioneer = sender self.auction_end_time = self.auction_start_time + duration self.is_running = True self.announce_interval = announce_interval self.late_bid_threshold = late_bid_threshold self.late_bid_extension = late_bid_extension if len(self.items) > 1: self.spam_raid_message("%s just started a mass auction for %d items." % (sender.name, len(self.items))) self.spam_raid_message(self.get_auction_list()) else: item_index = list(self.items.keys())[0] item = self.items[item_index] sql = "SELECT winning_bid FROM auction_log WHERE item_name LIKE ? ORDER BY time DESC LIMIT 5" bids = self.db.query(sql, [item]) if bids: avg_win_bid = int(sum(map(lambda x: x.winning_bid, bids)) / len(bids)) else: avg_win_bid = 0 bid_link = self.get_auction_list() bid_link = self.text.paginate_single(ChatBlob("Click to bid", bid_link.msg)) msg = "\n<yellow>----------------------------------------<end>\n" msg += "<yellow>%s<end> has just started an auction " \ "for <yellow>%s<end>.\n" % (sender.name, item) msg += "Average winning bid: <highlight>%s<end>\n" % avg_win_bid msg += "%s\n" % bid_link msg += "<yellow>----------------------------------------<end>" self.spam_raid_message(msg) self.create_next_announce_job()
def raid_active_cmd(self, request, _): if not self.raid: return self.NO_RAID_RUNNING_RESPONSE blob = "" count = 0 raider_names = [] for raider in self.raid.raiders: if count == 10: active_check_names = "/assist " active_check_names += "\\n /assist ".join(raider_names) blob += "[<a href='chatcmd://%s'>Active check</a>]\n\n" % active_check_names count = 0 raider_names.clear() raider_name = self.character_service.resolve_char_to_name( raider.active_id) akick_link = self.text.make_chatcmd( "Active kick", "/tell <myname> raid kick %s inactive" % raider.main_id) warn_link = self.text.make_chatcmd( "Warn", "/tell <myname> cmd %s missed active check, please give notice." % raider_name) blob += "<highlight>%s<end> [%s] [%s]\n" % (raider_name, akick_link, warn_link) raider_names.append(raider_name) count += 1 if len(raider_names) > 0: active_check_names = "/assist " active_check_names += "\\n /assist ".join(raider_names) blob += "[<a href='chatcmd://%s'>Active check</a>]\n\n" % active_check_names raider_names.clear() return ChatBlob("Active check", blob)
def discord_cmd(self, request): counter = 0 for cid, channel in self.channels.items(): if channel.relay_ao or channel.relay_dc: counter += 1 blob = "<header2>Info<end>\n" blob += "Status: " blob += "<green>Connected<end>\n" if self.is_connected( ) else "<red>Disconnected<end>\n" blob += "Channels available: <highlight>%d<end>\n\n" % counter blob += "<header2>Servers<end>\n" if self.servers: for server in self.servers: invites = self.text.make_chatcmd( "get invite", "/tell <myname> discord getinvite %s" % server.id) owner = server.owner.nick if server.owner.nick is not None else "Insufficient permissions" blob += "%s [%s]\n" % (server.name, invites) blob += " | member count: %s\n" % (str(len(server.members))) blob += " | owner: %s\n\n" % owner else: blob += "None\n\n" blob += "<header2>Subscribed channels<end>\n" for cid, channel in self.channels.items(): if channel.relay_ao or channel.relay_dc: a = "<green>On<end>" if channel.relay_ao else "<red>Off<end>" d = "<green>On<end>" if channel.relay_dc else "<red>Off<end>" blob += "<highlight>%s<end> :: <highlight>%s<end>\n" % ( channel.server_name, channel.channel_name) blob += " | relaying from AO [%s]\n" % a blob += " | relaying from Discord [%s]\n" % d blob += "\n\nDiscord Module written by <highlight>Vladimirovna<end>" return ChatBlob("Discord info", blob)
def loot_roll_cmd(self, request, _): if not self.leader_controller.can_use_command(request.sender.char_id, request.conn): return LeaderController.NOT_LEADER_MSG loot_list = self.get_loot_list(request.conn) if not loot_list: return "Loot list is empty." blob = "" for i, loot_item in loot_list.copy().items(): winners = [] if loot_item.bidders: if len(loot_item.bidders) <= loot_item.count: winners = loot_item.bidders.copy() loot_item.count = loot_item.count - len(loot_item.bidders) loot_item.bidders = [] else: for j in range(0, loot_item.count): winner = secrets.choice(loot_item.bidders) winners.append(winner) loot_item.bidders.remove(winner) loot_item.count = loot_item.count - 1 blob += "%d. %s\n" % (i, loot_item.get_item_str()) blob += " Winners: <highlight>%s</highlight>\n\n" % '</highlight>, <highlight>'.join( winners) if loot_item.count == 0: loot_list.pop(i) if len(blob) > 0: self.send_loot_message(ChatBlob("Roll results", blob), request.conn) else: return "No one was added to any loot."
def outgoing_org_message_event(self, event_type, event_data): org_abbreviation = self.get_org_abbreviation(event_data.conn) msg = org_abbreviation + " " sender = None if event_data.name: msg += self.text.make_charlink(event_data.name) + ": " sender = DictObject({ "char_id": event_data.char_id, "name": event_data.name }) if isinstance(event_data.message, ChatBlob): pages = self.text.paginate( ChatBlob(event_data.message.title, event_data.message.msg), event_data.conn, self.setting_service.get( "org_channel_max_page_length").get_value()) if len(pages) < 4: for page in pages: message = msg + page self.bot.send_message_to_other_org_channels( message, from_conn=event_data.conn) self.message_hub_service.send_message( self.MESSAGE_SOURCE, sender, org_abbreviation, page) else: message = msg + event_data.message.title self.bot.send_message_to_other_org_channels( message, from_conn=event_data.conn) self.message_hub_service.send_message(self.MESSAGE_SOURCE, sender, org_abbreviation, event_data.message.title) else: message = msg + event_data.message self.bot.send_message_to_other_org_channels( message, from_conn=event_data.conn) self.message_hub_service.send_message(self.MESSAGE_SOURCE, sender, org_abbreviation, event_data.message)
def config_list_cmd(self, channel, sender, reply, args): sql = """SELECT module, SUM(CASE WHEN enabled = 1 THEN 1 ELSE 0 END) count_enabled, SUM(CASE WHEN enabled = 0 THEN 1 ELSE 0 END) count_disabled FROM (SELECT module, enabled FROM command_config UNION SELECT module, enabled FROM event_config UNION SELECT module, 2 FROM setting) t GROUP BY module ORDER BY module ASC""" data = self.db.query(sql) count = len(data) blob = "" current_group = "" for row in data: parts = row.module.split(".") group = parts[0] module = parts[1] if group != current_group: current_group = group blob += "\n<header2>" + current_group + "<end>\n" blob += self.text.make_chatcmd(module, "/tell <myname> config mod " + row.module) + " " if row.count_enabled > 0 and row.count_disabled > 0: blob += "<yellow>Partial<end>" elif row.count_disabled == 0: blob += "<green>Enabled<end>" else: blob += "<red>Disabled<end>" blob += "\n" reply(ChatBlob("Config (%d)" % count, blob))
def config_cmdlist_cmd(self, request, _, named_params): sql = "SELECT access_level, channel, enabled, command, module, sub_command FROM command_config" params = [] if named_params.access_level: sql += " WHERE access_level = ?" params.append(named_params.access_level) sql += " ORDER BY module, command, sub_command, channel" data = self.db.query(sql, params) blob = "" current_module = "" current_command_key = "" count = 0 temp_rows = [] for row in data: if current_module != row.module: if temp_rows: blob += self.display_row_data(temp_rows) temp_rows = [] blob += "\n<pagebreak><header2>%s<end>\n" % row.module current_module = row.module current_command_key = "" command_key = self.command_service.get_command_key(row.command, row.sub_command) if current_command_key != command_key: if temp_rows: blob += self.display_row_data(temp_rows) temp_rows = [] count += 1 blob += "%s - " % (self.text.make_chatcmd(command_key, "/tell <myname> config cmd " + command_key)) current_command_key = command_key temp_rows.append(row) if temp_rows: blob += self.display_row_data(temp_rows) return ChatBlob(self.getresp("module/config", "cmdlist_commands", {"amount": count}), blob)
def raid_cmd(self, request): if not self.raid: return self.NO_RAID_RUNNING_RESPONSE blob = "" blob += "Name: <highlight>%s<end>\n" % self.raid.raid_name blob += "Started By: <highlight>%s<end>\n" % self.raid.started_by.name blob += "Started At: <highlight>%s<end> (%s ago)\n" % (self.util.format_datetime(self.raid.started_at), self.util.time_to_readable(int(time.time()) - self.raid.started_at)) blob += "Minimum Level: <highlight>%d<end>\n" % self.raid.raid_min_lvl blob += "Maximum Characters: <highlight>%s<end>\n" % (self.raid.raid_limit or "No Limit") blob += "Status: %s" % ("<green>Open<end>" if self.raid.is_open else "<red>Closed<end>") if self.raid.is_open: blob += " (%s)" % self.text.make_chatcmd("Join", "/tell <myname> raid join") blob += "\n\n" if self.raid.raid_orders: blob += "<header2>Orders<end>\n" blob += self.raid.raid_orders + "\n\n" blob += "<header2>Raiders<end>\n" for raider in self.raid.raiders: if raider.is_active: blob += self.text.format_char_info(raider.get_active_char()) + "\n" return ChatBlob("Raid Status", blob)
def recipe_search_cmd(self, request, search, named_params): page = int(named_params.page or "1") page_size = 30 offset = (page - 1) * page_size data = self.db.query("SELECT * FROM recipe WHERE recipe <EXTENDED_LIKE=0> ? ORDER BY name ASC", [search], extended_like=True) count = len(data) paged_data = data[offset:offset + page_size] blob = "" if count > page_size: if page > 1 and len(paged_data) > 0: blob += " " + self.text.make_chatcmd("<< Page %d" % (page - 1), self.get_chat_command(search, page - 1)) if offset + page_size < len(data): blob += " Page " + str(page) blob += " " + self.text.make_chatcmd("Page %d >>" % (page + 1), self.get_chat_command(search, page + 1)) blob += "\n\n" for row in paged_data: blob += self.text.make_tellcmd(row.name, "recipe %d" % row.id) + "\n" return ChatBlob("Recipes Matching '%s' (%d - %d of %d)" % (search, offset + 1, min(offset + page_size, count), count), blob)
def discord_cmd(self, request): servers = "" if self.client and self.client.guilds: for server in self.client.guilds: invites = self.text.make_tellcmd( self.getresp("module/discord", "get_invite"), "discord getinvite %s" % server.id) owner = server.owner.nick or re.sub( pattern=r"#\d+", repl="", string=str(server.owner)) servers += self.getresp( "module/discord", "server", { "server_name": server.name, "invite": invites, "m_count": str(len(server.members)), "owner": owner }) else: servers += self.getresp("module/discord", "no_server") subs = "" for channel in self.get_text_channels(): subs += self.getresp("module/discord", "sub", { "server_name": channel.guild.name, "channel_name": channel.name }) status = self.getresp( "module/discord", "connected" if self.is_connected() else "disconnected") blob = self.getresp( "module/discord", "blob", { "connected": status, "count": len(self.get_text_channels()), "servers": servers, "subs": subs }) return ChatBlob(self.getresp("module/discord", "title"), blob)
def config_list_cmd(self, request): sql = """SELECT module, SUM(CASE WHEN enabled = 1 THEN 1 ELSE 0 END) count_enabled, SUM(CASE WHEN enabled = 0 THEN 1 ELSE 0 END) count_disabled FROM (SELECT module, enabled FROM command_config UNION SELECT module, enabled FROM event_config WHERE is_hidden = 0 UNION SELECT module, 2 FROM setting) t GROUP BY module ORDER BY module ASC""" data = self.db.query(sql) count = len(data) blob = "" current_group = "" for row in data: parts = row.module.split(".") group = parts[0] module = parts[1] if group != current_group: current_group = group blob += "\n<header2>" + current_group + "</header2>\n" blob += self.text.make_tellcmd(module, "config mod " + row.module) + " " if row.count_enabled > 0 and row.count_disabled > 0: blob += "Partial" else: blob += "<green>Enabled</green>" if row.count_disabled == 0 else "<red>Disabled</red>" blob += "\n" return ChatBlob(f"Config ({count})", blob)
def handle_discord_invite_event(self, event_type, event_data): char_name = event_data[0] invites = event_data[1] blob = "" server_invites = "" if len(invites) > 0: for invite in invites: link = self.text.make_chatcmd( self.getresp("module/discord", "join"), "/start %s" % invite.url) timeleft = "Permanent" if invite.max_age == 0 else str( datetime.timedelta(seconds=invite.max_age)) used = str(invite.uses) if invite.uses is not None else "N/A" useleft = str( invite.max_uses) if invite.max_uses is not None else "N/A" channel = self.getresp("module/discord", "inv_channel", {"channel": invite.channel.name})\ if invite.channel is not None else None server_invites += self.getresp( "module/discord", "invite", { "server": invite.guild.name, "link": link, "time_left": timeleft, "count_used": used, "count_left": useleft, "channel": channel }) blob += self.getresp("module/discord", "blob_invites", {"invites": server_invites}) else: blob += self.getresp("module/discord", "no_invites") char_id = self.character_service.resolve_char_to_id(char_name) self.bot.send_private_message( char_id, ChatBlob(self.getresp("module/discord", "invite_title"), blob))
def get_online_output(self): blob = "" count = 0 for channel, _ in self.channels: online_list = self.get_online_characters(channel) if len(online_list) == 0: continue blob += "<header2>%s Channel</header2>\n" % channel current_main = "" for row in online_list: if current_main != row.main: count += 1 blob += "\n%s\n" % self.text.make_tellcmd( row.main, "alts %s" % row.main) current_main = row.main afk = "" if row.afk_dt > 0: afk = " - <highlight>%s (%s ago)</highlight>" % ( row.afk_reason, self.util.time_to_readable( int(time.time()) - row.afk_dt)) org_info = "" if channel == self.PRIVATE_CHANNEL: if row.org_name: org_info = ", %s of %s" % (row.org_rank_name, row.org_name) blob += " | %s (%d/<green>%d</green>) %s %s%s%s\n" % ( row.name, row.level or 0, row.ai_level or 0, row.faction, row.profession, afk, org_info) blob += "\n\n" return ChatBlob("Online (%d)" % count, blob)
def account_log_entry_cmd(self, _1, _2, log_id: int): log_entry = self.db.query_single("SELECT * FROM points_log WHERE log_id = ?", [log_id]) if log_entry: char_name = self.character_service.resolve_char_to_name(log_entry.char_id) leader_name = self.character_service.resolve_char_to_name(log_entry.leader_id) blob = "Log entry ID: <highlight>%d<end>\n" % log_id blob += "Affecting account: <highlight>%s<end>\n" % char_name blob += "Action by: <highlight>%s<end>\n" % leader_name blob += "Type: <highlight>%s<end>\n" % ("Management" if log_entry.audit == 0 else "Altering of points") blob += "Reason: <highlight>%s<end>\n" % log_entry.reason action_links = None if log_entry.audit == 0: if "closed" in log_entry.reason: action_links = self.text.make_chatcmd("Open the account", "/tell <myname> account create %s" % char_name) elif "re-enabled" in log_entry.reason: action_links = self.text.make_chatcmd("Close the account", "/tell <myname> account close %s" % char_name) else: if log_entry.audit < 0: reason = "Points from event (%d) has been retracted, %d points have been added." \ % (log_id, (-1*log_entry.audit)) action_links = self.text.make_chatcmd("Retract", "/tell <myname> bank give %d %s %s" % ((-1*log_entry.audit), char_name, reason)) else: reason = "Points from event (%d) has been retracted, %d points have been deducted." \ % (log_id, log_entry.audit) action_links = self.text.make_chatcmd("Retract", "/tell <myname> bank take %d %s %s" % (log_entry.audit, char_name, reason)) blob += "Actions available: [%s]\n" % (action_links if action_links is not None else "No actions available") return ChatBlob("Log entry (%d)" % log_id, blob) return "No log entry with given ID (%d)" % log_id
def leprocs_show_command(self, request, prof_name): profession = self.util.get_profession(prof_name) if not profession: return "Could not find profession <highlight>%s</highlight>." % prof_name data = self.db.query( "SELECT * FROM leprocs WHERE profession LIKE ? ORDER BY proc_type ASC, research_lvl DESC", [profession]) proc_type = "" blob = "" for row in data: if proc_type != row.proc_type: proc_type = row.proc_type blob += "\n<highlight>%s</highlight>\n" % proc_type blob += "<pagebreak>[%d] %s <orange>%s</orange> %s <green>%s</green>\n" % ( row.research_lvl, row.name, row.modifiers, row.duration, row.proc_trigger) blob += "\n\nNote: Offensive procs have a 5% chance of firing every time you attack; Defensive procs have a 10% chance of firing every time something attacks you." blob += "\n\nProc info provided by Wolfbiter (RK1), Gatester (RK2)" return ChatBlob("%s LE Procs" % profession, blob)
def research_span_command(self, request, research_level1, research_level2): if research_level1 > 10 or research_level1 < 1 or research_level2 > 10 or research_level2 < 1: return "Research level must be between 1 and 10." elif research_level1 == research_level2: return "You must specify different research levels." if research_level1 > research_level2: # swap researches so the lower is research_level1 and higher is research_level2 research_level1, research_level2 = research_level2, research_level1 row = self.db.query_single( "SELECT SUM(sk) AS total_sk, MAX(levelcap) AS levelcap FROM research WHERE level > ? AND level <= ?", [research_level1, research_level2]) blob = "You must be <highlight>Level %d</highlight> to reach Research Level <highlight>%d.</highlight>\n" % ( row.levelcap, research_level2) blob += "It takes <highlight>%s SK</highlight> to go from Research Level <highlight>%d</highlight> to Research Level <highlight>%d</highlight> per research line.\n\n" \ % (self.util.format_number(row.total_sk), research_level1, research_level2) blob += "This equals <highlight>%s XP</highlight>." % self.util.format_number( row.total_sk * 1000) return ChatBlob( "Research Levels %d - %d" % (research_level1, research_level2), blob)
def get_search_results(self, item_type, skill): data = self.db.query( "SELECT aodb.*, b.amount " "FROM aodb " "JOIN item_types i ON aodb.highid = i.item_id " "JOIN item_buffs b ON aodb.highid = b.item_id " "JOIN skills s ON b.attribute_id = s.id " "WHERE i.item_type LIKE ? AND s.id = ? " "ORDER BY amount DESC", [item_type, skill.id]) if len(data) == 0: return "No items found of type <highlight>%s<end> that buff <highlight>%s<end>." % ( item_type, skill.name) else: blob = "" for row in data: blob += "%s (%d)\n" % (self.text.make_item( row.lowid, row.highid, row.highql, row.name), row.amount) blob += self.get_footer() return ChatBlob( "Whatbuffs - %s %s (%d)" % (item_type, skill.name, len(data)), blob)
def get_loot_list_display(self, conn: Conn): blob = "" for i, loot_item in self.get_loot_list(conn).items(): bidders = loot_item.bidders item_image = loot_item.get_item_image() if item_image: blob += item_image + "\n" blob += "%d. %s x%d" % (i, loot_item.get_item_str(), loot_item.count) add_to_loot = self.text.make_tellcmd("Join", "loot join %d" % i) remove_from_loot = self.text.make_tellcmd("Leave", "loot leave") blob += " [%s] [%s]\n" % (add_to_loot, remove_from_loot) if len(bidders) > 0: blob += "Bidders: %s\n" % ', '.join(bidders) else: blob += "Bidders: -\n" blob += "\n\n" return ChatBlob("Loot (%d)" % len(self.get_loot_list(conn)), blob)
def get_search_results_blob(self, search, page_number): page_size = 30 offset = (page_number - 1) * page_size data = self.db.query( "SELECT * FROM recipe WHERE recipe <EXTENDED_LIKE=0> ? ORDER BY name ASC", [search], extended_like=True) count = len(data) paged_data = data[offset:offset + page_size] blob = "" if len(data) > 0: blob += self.text.get_paging_links(f"recipe {search}", page_number, offset + page_size < len(data)) blob += "\n\n" for row in paged_data: blob += self.text.make_tellcmd(row.name, "recipe %d" % row.id) + "\n" return ChatBlob( "Recipes Matching '%s' (%d - %d of %d)" % (search, offset + 1, min(offset + page_size, count), count), blob)
def fullauto_cmd(self, request, weapon_attack, weapon_recharge, full_auto_recharge, full_auto_skill): full_auto_info = self.get_full_auto_info(weapon_attack, weapon_recharge, full_auto_recharge, full_auto_skill) blob = "Attack: <highlight>%.2f secs</highlight>\n" % weapon_attack blob += "Recharge: <highlight>%.2f secs</highlight>\n" % weapon_recharge blob += "Full Auto Recharge: <highlight>%d</highlight>\n" % full_auto_recharge blob += "Full Auto Skill: <highlight>%d</highlight>\n\n" % full_auto_skill blob += "Full Auto Recharge: <highlight>%d secs</highlight>\n" % full_auto_info.recharge blob += "Max Number of Bullets: <highlight>%d</highlight>\n\n" % full_auto_info.max_bullets blob += "You need <highlight>%d</highlight> Full Auto Skill to cap your recharge at <highlight>%d secs</highlight>.\n\n" % ( full_auto_info.skill_cap, full_auto_info.hard_cap) blob += "From <highlight>0 to 10K</highlight> damage, the bullet damage is unchanged.\n" blob += "From <highlight>10K to 11.5K</highlight> damage, each bullet damage is halved.\n" blob += "From <highlight>11K to 15K</highlight> damage, each bullet damage is halved again.\n" blob += "<highlight>15K</highlight> is the damage cap." return ChatBlob("Full Auto Results", blob)
def ofabweapons_show_command(self, request, ql1, weapon_name, ql2): weapon_name = weapon_name.capitalize() ql = ql1 or ql2 or 300 weapon = self.db.query_single( "SELECT type, vp FROM ofab_weapons w, ofab_weapons_cost c WHERE w.name LIKE ? AND c.ql = ?", [weapon_name, ql]) if not weapon: return "Ofab Weapon <highlight>%s</highlight> for QL <highlight>%d</highlight> does not exist." % ( weapon_name, ql) type_ql = round(ql * 0.8) type_link = self.text.make_tellcmd( "Kyr'Ozch Bio-Material - Type %d" % weapon.type, "bioinfo %d %d" % (weapon.type, type_ql)) blob = "Upgrade with %s (minimum QL %d)\n\n" % (type_link, type_ql) data = self.db.query( "SELECT ql FROM ofab_weapons_cost ORDER BY ql ASC") for row in data: blob += self.text.make_tellcmd( row.ql, "ofabweapons %s %d" % (weapon_name, row.ql)) + " " blob += "\n\n" for i in range(1, 7): item = self.items_controller.find_by_name("Ofab %s Mk %d" % (weapon_name, i), ql=ql) blob += "<pagebreak>" + self.text.format_item(item, ql=ql) if i == 1: blob += " (<highlight>%d</highlight> VP)" % weapon.vp blob += "\n" return ChatBlob("Ofab %s (QL %d)" % (weapon_name, ql), blob)
def orglist_character_cmd(self, request, search): if search.isdigit(): org_id = int(search) else: orgs = self.pork_service.find_orgs(search) num_orgs = len(orgs) if num_orgs == 0: char_info = self.pork_service.get_character_info(search) if char_info: if not char_info.org_id: return "<highlight>%s<end> does not appear to belong to an org." % search.capitalize() else: org_id = char_info.org_id else: return "Could not find character or org <highlight>%s<end>." % search elif num_orgs == 1: org_id = orgs[0].org_id else: blob = "" for org in orgs: blob += self.text.make_chatcmd("%s (%d)" % (org.org_name, org.org_id), "/tell <myname> orglist %d" % org.org_id) + "\n" return ChatBlob("Org List (%d)" % num_orgs, blob) self.start_orglist_lookup(request.reply, org_id)
def alien_weapon_bio(self, bio_type, ql): name = "Kyr'Ozch Bio-Material - Type %s" % bio_type blob = self.display_item(name, ql) + "\n\n" ee_cl_req = math.floor(ql * 4.5) blob += f"It will take <highlight>{ee_cl_req}</highlight> EE & CL (<highlight>4.5 * QL</highlight>) to analyze the Bio-Material.\n\n" specials = self.db.query_single("SELECT specials FROM alien_weapon_specials WHERE type = ?", [bio_type]).specials blob += f"<highlight>Adds {specials} to:</highlight>\n" # Ensures that the maximum AI weapon that combines into doesn't go over QL 300 when the user presents a QL 271+ bio-material max_ai_type = math.floor(ql / 0.9) if max_ai_type > 300 or max_ai_type < 1: max_ai_type = 300 data = self.db.query("SELECT * FROM alien_weapons WHERE type = ?", [bio_type]) for row in data: blob += self.display_item(row.name, max_ai_type) + "\n" blob += self.get_weapon_info(max_ai_type) blob += "\n\n<yellow>Tradeskilling info added by Mdkdoc420</yellow>" return ChatBlob("%s (QL %d)" % (name, ql), blob)
def config_module_list_cmd(self, channel, sender, reply, args): module = args[1].lower() blob = "" data = self.db.query("SELECT name FROM setting WHERE module = ? ORDER BY name ASC", [module]) if data: blob += "<header2>Settings<end>\n" for row in data: setting = self.setting_manager.get(row.name) blob += setting.get_description() + ": " + self.text.make_chatcmd(setting.get_display_value(), "/tell <myname> config setting " + row.name) + "\n" data = self.db.query("SELECT DISTINCT command, sub_command FROM command_config WHERE module = ? ORDER BY command ASC", [module]) if data: blob += "\n<header2>Commands<end>\n" for row in data: command_key = self.command_manager.get_command_key(row.command, row.sub_command) blob += self.text.make_chatcmd(command_key, "/tell <myname> config cmd " + command_key) + "\n" data = self.db.query("SELECT event_type, event_sub_type, handler, description " "FROM event_config WHERE module = ? " "ORDER BY event_type, handler ASC", [module]) if data: blob += "\n<header2>Events<end>\n" for row in data: event_type_key = self.event_manager.get_event_type_key(row.event_type, row.event_sub_type) blob += row.event_type + " - " + row.description blob += " " + self.text.make_chatcmd("On", "/tell <myname> config event " + event_type_key + " " + row.handler + " enable") blob += " " + self.text.make_chatcmd("Off", "/tell <myname> config event " + event_type_key + " " + row.handler + " disable") blob += "\n" if blob: reply(ChatBlob("Module (" + module + ")", blob)) else: reply("Could not find module <highlight>%s<end>" % module)
def premade_list_cmd(self, request): blob = "<header2>Professions</header2>\n" for row in self.db.query( "SELECT Name FROM Profession WHERE ID IN (SELECT ProfessionID FROM premade_implant) ORDER BY Name ASC" ): blob += self.text.make_tellcmd(row.Name, "premade %s" % row.Name) + "\n" blob += "\n<header2>Slots</header2>\n" for row in self.db.query( "SELECT * FROM ImplantType ORDER BY ImplantTypeID ASC"): blob += self.text.make_tellcmd(row.Name, "premade %s" % row.ShortName) + "\n" blob += "\n<header2>Modifiers</header2>\n" sql = "SELECT LongName FROM Cluster WHERE ClusterID IN " \ "(SELECT ShinyClusterID From premade_implant UNION SELECT BrightClusterID FROM premade_implant UNION SELECT FadedClusterID FROM premade_implant) " \ "AND ClusterID != 0 " \ "ORDER BY LongName ASC" for row in self.db.query(sql): blob += self.text.make_tellcmd(row.LongName, "premade %s" % row.LongName) + "\n" return ChatBlob("Premade Implant", blob)
def get_loot_list(self): blob = "" for i, loot_item in self.loot_list.items(): item = loot_item.item bidders = loot_item.bidders increase_link = self.text.make_chatcmd("+", "/tell <myname> loot increase %d" % i) decrease_link = self.text.make_chatcmd("-", "/tell <myname> loot decrease %d" % i) blob += "%d. %s " % (i, self.text.make_item(item.low_id, item.high_id, item.ql, item.name)) blob += "x%s [%s|%s]\n" % (loot_item.count, increase_link, decrease_link) if len(bidders) > 0: blob += " | %s\n" % ', '.join(bidders) else: blob += " | No bidders\n" add_to_loot = self.text.make_chatcmd("Add to", "/tell <myname> loot add %d" % i) remove_from_loot = self.text.make_chatcmd("Remove from", "/tell <myname> loot rem") remove_item = self.text.make_chatcmd("Remove item", "/tell <myname> loot remitem %d" % i) blob += " | [%s] [%s] [%s]\n\n" % (add_to_loot, remove_from_loot, remove_item) return ChatBlob("Loot (%d)" % len(self.loot_list), blob)
def handle_discord_invite_event(self, event_type, event_data): sender = event_data[0] invites = event_data[1] blob = "<header2>Available invites<end>\n" if len(invites) > 0: for invite in invites: link = self.text.make_chatcmd("join", "/start %s" % invite.url) timeleft = "Permanent" if invite.max_age == 0 else str(datetime.timedelta(seconds=invite.max_age)) used = str(invite.uses) if invite.uses is not None else "N/A" useleft = str(invite.max_uses) if invite.max_uses is not None else "N/A" channel = " | for channel: %s\n" % invite.channel.name if invite.channel is not None else None blob += "%s [%s]\n" % (invite.server.name, link) blob += " | life time: %s\n" % timeleft blob += " | used: %s\n" % used blob += " | uses left: %s\n" % useleft blob += channel blob += "\n" else: blob += "None available, maybe the bot user does not have sufficient permissions to see invites, or no invites exists.\n\n" self.bot.send_private_message(sender, ChatBlob("Discord invites", blob))
def cloak_command(self, request, flag_params): t = int(time.time()) if flag_params.all: blob = "" for _id, conn in self.bot.get_conns(lambda x: x.is_main and x.org_id): row = self.db.query_single("SELECT c.char_id, c.action, c.created_at, p.name FROM cloak_status c LEFT JOIN player p ON c.char_id = p.char_id " "WHERE c.org_id = ? ORDER BY created_at DESC LIMIT 1", [conn.org_id]) org_name = conn.get_org_name() if row: action = self.get_cloak_status_display(row.action) time_str = self.util.time_to_readable(t - row.created_at) history_link = self.text.make_tellcmd("History", f"cloak history {conn.org_id}") blob += f"{org_name} - {action} [{time_str} ago] {history_link}\n" else: blob += f"{org_name} - Unknown\n" title = "Cloak Status" return ChatBlob(title, blob) else: conn = request.conn if not conn.org_id: return "This bot is not a member of an org." row = self.db.query_single("SELECT c.char_id, c.action, c.created_at, p.name FROM cloak_status c LEFT JOIN player p ON c.char_id = p.char_id " "WHERE c.org_id = ? ORDER BY created_at DESC LIMIT 1", [conn.org_id]) org_name = conn.get_org_name() if row: action = self.get_cloak_status_display(row.action) time_str = self.util.time_to_readable(t - row.created_at) return f"{org_name} - {action} [{time_str} ago]" else: return f"{org_name} - Unknown cloak status"
def format_help_text(self, topic, help_text): return ChatBlob("Help (" + topic + ")", help_text)
def alts_list_cmd(self, request): alts = self.alts_service.get_alts(request.sender.char_id) blob = self.format_alt_list(alts) return ChatBlob(self.getresp("module/alts", "list", {"char": alts[0].name, "amount": len(alts)}), blob)