Added the option to !opt-in/opt-out [onlinebot only]

Fixed command & event threading
Events are now threaded by event_type (i.e. all buddy_logon events get ran in the same one)
Added default preferences
Fixed recipe loading for multiple installs (i.e. on different machines)
This commit is contained in:
2021-08-27 13:58:47 +02:00
parent d0c8c1744c
commit c04f76c0db
24 changed files with 258 additions and 122 deletions
@@ -25,7 +25,7 @@ class RandomController:
self.command_alias_service.add_alias("verify", "roll verify")
self.command_alias_service.add_alias("lootorder", "random")
@command(command="random", params=[Any("items")], access_level="all",
@command(command="random", params=[Any("items")], access_level="member",
description="Randomly order a list of elements",
extended_description="Enter a space-delimited list of items to randomize.")
def random_command(self, _, items):
@@ -33,19 +33,19 @@ class RandomController:
random.shuffle(items)
return " ".join(items)
@command(command="roll", params=[Const("verify"), Int("roll_id")], access_level="all",
@command(command="roll", params=[Const("verify"), Int("roll_id")], access_level="member",
description="Verify a roll that happened")
def roll_verify_command(self, _, _1, roll_id):
row = self.db.query_single("SELECT * FROM roll WHERE id = ?", [roll_id])
if not row:
return "Could not find roll with id <highlight>%d</highlight>." % roll_id
return f"Could not find roll with id <highlight>{roll_id:d}</highlight>."
else:
time_string = self.util.time_to_readable(int(time.time()) - row.created_at)
name = self.character_service.resolve_char_to_name(row.char_id)
return "<highlight>%s</highlight> rolled by <highlight>%s</highlight> %s ago. Possible options: %s." % (
row.result, name, time_string, row.options)
return f"<highlight>{row.result}</highlight> rolled by <highlight>{name}</highlight> " \
f"{time_string} ago. Possible options: {row.options}."
@command(command="roll", params=[Int("start_value", is_optional=True), Int("end_value")], access_level="all",
@command(command="roll", params=[Int("start_value", is_optional=True), Int("end_value")], access_level="member",
description="Roll a number between 1 and a number",
extended_description="The given numbers are included in the roll.")
def roll_number_command(self, request, start_value, end_value):
@@ -64,7 +64,7 @@ class RandomController:
f"To verify do /tell <myname> verify {self.db.last_insert_id():d}"
# Keep this method at the bottom of file otherwise it will precede over all other commands
@command(command="roll", params=[Any("items")], access_level="all",
@command(command="roll", params=[Any("items")], access_level="member",
description="Roll a random value",
extended_description="Enter a space-delimited list of values to roll")
def roll_text_variables_command(self, request, items):
@@ -17,7 +17,7 @@ class WhompahController:
self.db.create_view("whompah_cities")
self.db.create_view("whompah_cities_rel")
@command(command="whompah", params=[], access_level="all",
@command(command="whompah", params=[], access_level="member",
description="Show list of whompah cities")
def whompah_list_cmd(self, request):
cities = self.db.query("SELECT id, city_name, zone, faction, short_name FROM whompah_cities ORDER BY city_name")
@@ -29,7 +29,7 @@ class WhompahController:
return ChatBlob("Whompah Cities", blob)
@command(command="whompah", params=[Any("city1"), Any("city2")], access_level="all",
@command(command="whompah", params=[Any("city1"), Any("city2")], access_level="member",
description="Show whompah route between two cities")
def whompah_travel_cmd(self, request, city_name1, city_name2):
city1 = self.get_whompah_city(city_name1)
@@ -53,7 +53,7 @@ class WhompahController:
path = self.format_path(self.find_path(cities, city1.id, city2.id))
return " -> ".join(path)
@command(command="whompah", params=[Any("city")], access_level="all",
@command(command="whompah", params=[Any("city")], access_level="member",
description="Show whompah destinations for a city")
def whompah_city_cmd(self, request, city_name):
city = self.get_whompah_city(city_name)
@@ -265,7 +265,7 @@ class LootListsController:
@command(command="totwh", params=[Options(
["binyacht", "guardian", "summoner", "loremaster", "nematet", "aegis", "lien", "gartua", "aztur", "khalum",
"uklesh", "gen", "armor"])],
description="Get list of items from Temple of Three Winds", access_level="all")
description="Get list of items from Temple of Three Winds", access_level="member")
def totwh_loot_cmd(self, _, category_name):
category = self.get_real_category_name(category_name)
items = self.get_items("Temple of Three Winds (HL)", category)
@@ -274,7 +274,7 @@ class LootListsController:
else:
return "No loot registered for <highlight>%s<end>." % category_name
@command(command="totwh", params=[], description="Get list of items from Temple of Three Winds", access_level="all")
@command(command="totwh", params=[], description="Get list of items from Temple of Three Winds", access_level="member")
def totwh_tables_cmd(self, _):
return ChatBlob("Temple of Three Winds (HL) loot tables",
self.build_overview("Temple of Three Winds (HL)", "totwh"))
+11 -9
View File
@@ -52,7 +52,7 @@ class MailController:
def logon_event(self, _, data):
if not self.bot.is_ready():
return
if data.account.disabled == 1:
if not self.account_service.simple_checks(data.account):
return
if "mail" in self.buddy_service.get_buddy(data.packet.char_id)["types"]:
self.job_schedule.delayed_job(self.send_mail, 16, data.packet.char_id, self.get_mails(data.packet.char_id))
@@ -129,8 +129,10 @@ class MailController:
recipient = self.account_service.get_account(receiver.char_id)
if not recipient:
return f"No account for <highlight>{receiver.name}</highlight> found."
if recipient.member == -1 or recipient.disabled == 1:
return f"The Character <highlight>{recipient.name}</highlight> has " \
# if recipient.member == -1 or recipient.disabled == 1:
if not self.account_service.simple_checks(recipient):
return f"The Character <highlight>{recipient.name}</highlight> has " \
f"no active account in <highlight><myname></highlight>."
self.db.exec("INSERT INTO mail(sender, recipient, text, sent_at) VALUES(?, ?, ?, ?)",
[sender.sender.char_id, recipient.main, message, time.time()])
@@ -152,12 +154,12 @@ class MailController:
group = self.account_service.get_group_tag(recipient)
users = []
if group:
if group == "all":
if sender.sender.access_level['level'] > 20:
return "This group is unavailable."
users = self.account_service.get_all_members()
else:
users = self.account_service.get_by_group(group)
# if group == "all":
# if sender.sender.access_level['level'] > 20:
# return "This group is unavailable."
# users = self.account_service.get_all_members()
# else:
users = self.account_service.get_by_group(group)
elif not group:
return f"Sorry, but the group <highlight>{recipient}</highlight> does not exist. " \
+4 -1
View File
@@ -122,7 +122,8 @@ hh:mm - DD.MM.YYYY
return
if "member" in self.buddy_service.get_buddy(data.packet.char_id)["types"]:
account = data.account
if account.disabled == 1:
# Apply standard checks. (User Banned, Account disabled, ...)
if not self.account_service.simple_checks(data.account):
return
if self.db.query_single("SELECT * from org_bots where char_id=?", [data.packet.char_id]):
return
@@ -138,6 +139,8 @@ hh:mm - DD.MM.YYYY
self.job_schedule.delayed_job(self.send_news, 15, user, self.account_service.get_alts(account.main),
discord,
self.preferences.get_pref_view_small(account))
# This one is kinda redudant now that the simple checks get done above, will remove it in the future.
if account.last_seen == 0 and self.setting_service.get_value('is_alliance_bot') == "1":
self.bot.send_mass_message(data.packet.char_id, self.INFO)
+4 -5
View File
@@ -35,13 +35,12 @@ class OnlineDisplay:
blob, org, priv, notify = online
postfix = []
if org > 0:
postfix.append(f"Org: {org}")
postfix.append(f"<notice>Org: {org}</notice>")
if priv > 0:
postfix.append(f"Priv: {priv}")
postfix.append(f"<highlight>Priv: {priv}</notice>")
if notify > 0:
postfix.append(f"Buddylist: {notify}")
blob = ChatBlob(title, blob)
blob.page_postfix = f" ({f', '.join(postfix)})"
postfix.append(f"<notice>Buddylist: {notify}</notice>")
blob = ChatBlob(title, blob, suffix=f" ({f', '.join(postfix)})")
return blob
def format_by_channel_main(self, query, params):
+3 -3
View File
@@ -20,7 +20,7 @@ class QuoteController:
"created_at INT NOT NULL, "
"content VARCHAR(4096) NOT NULL)")
@command(command="quote", params=[], access_level="all",
@command(command="quote", params=[], access_level="member",
description="Show a random quote")
def quote_command(self, request):
quote = self.get_quote_info()
@@ -30,7 +30,7 @@ class QuoteController:
else:
return "There are no quotes to display."
@command(command="quote", params=[Int("quote_id")], access_level="all",
@command(command="quote", params=[Int("quote_id")], access_level="member",
description="Show a specific quote")
def quote_view_command(self, _, quote_id):
quote = self.get_quote_info(quote_id)
@@ -40,7 +40,7 @@ class QuoteController:
else:
return f"Could not find quote with ID <highlight>{quote_id:d}</highlight>."
@command(command="quote", params=[Const("add"), Any("quote")], access_level="all",
@command(command="quote", params=[Const("add"), Any("quote")], access_level="member",
description="Show a specific quote")
def quote_add_command(self, request, _, quote):
if len(quote) > 4096:
+1 -1
View File
@@ -50,7 +50,7 @@ class RecipeController:
recipe = self.find_recipe(recipe_id, recipes)
if recipe:
recipes.remove(recipe)
if recipe.dt == dt:
if recipe.dt >= dt:
continue
self.update_recipe(recipe_dir, recipe_id, file_type, dt)