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
+15 -9
View File
@@ -15,6 +15,7 @@ from core.setting_service import SettingService
from core.text import Text
from core.tyrbot import Tyrbot
from core.util import Util
from modules.core.accounting.services.account_service import AccountService
from modules.core.ban.ban_service import BanService
@@ -62,6 +63,7 @@ class RaidController:
self.setting_service: SettingService = registry.get_instance("setting_service")
self.ban: BanService = registry.get_instance("ban_service")
self.private_channel_service: PrivateChannelService = registry.get_instance("private_channel_service")
self.account_service: AccountService = registry.get_instance("account_service")
@command(command="raid", params=[Const("desc"), Any("<description>")],
description="Change the title of the Raid", access_level="leader")
@@ -119,7 +121,9 @@ class RaidController:
if self.raid:
return "There's already a raid running."
self.raid = Raid(request.sender, request.sender.access_level["level"])
self.raid.bot = self.bot.get_char_name()
# after I saw myself sending raid invites with the wrong bot reference by accident atleast once,
# the default is being set to allianceraid again.
self.raid.bot = "allianceraid" # self.bot.get_char_name()
self.raid.last_action = time.time()
spam = f"""
________________
@@ -146,7 +150,7 @@ class RaidController:
return "There's no raid running."
def blob(label, msg):
return "<a href=\"text://%s\">%s</a>" % (textwrap.dedent(msg), textwrap.dedent(label))
return f"<a href=\"text://{textwrap.dedent(msg)}\">{textwrap.dedent(label)}</a>"
last = time.time()
if self.raid.last_spam + 5 * 60 > last:
@@ -178,7 +182,7 @@ class RaidController:
"""
subtile = f"""<yellow>[<green>{request.sender.name}</green>]: Raid Starting: <notice>{self.raid.raid_desc}</notice> -- use <notice>/tell {self.raid.bot} join</notice> to participate or {click_here}</yellow></yellow> """
# noinspection SqlAggregates
players = self.db.query("SELECT p.*, a.subtile_spam, a.raid_invite, a.raid_spam from online o "
players = self.db.query("SELECT p.*, a.subtile_spam, a.raid_invite, a.raid_spam, a.main, a.disabled, a.member from online o "
"left join player p on o.char_id = p.char_id "
"left join account a on a.char_id=(select main from account where char_id=o.char_id) "
"where p.level >= ? AND ((a.raid_invite=1 or a.raid_spam = 1) "
@@ -189,18 +193,20 @@ class RaidController:
"AND o.bot=? group by o.char_id "
"ORDER BY p.profession, p.name, p.level, p.org_rank_id;",
[self.raid.min_level, self.bot.get_char_id()])
self.bot.send_mass_message(request.sender.char_id, f"Sending invites to {len(players)} Players...")
self.bot.send_mass_message(request.sender.char_id, f"Attempting to send {len(players)} invites...")
info = "Sent invites to:"
prof = ""
count = len(players)
for i in players:
if not self.account_service.simple_checks(i):
count -= 1
continue
if prof != i.profession:
info += "\n\n<img src=tdb://id:GFX_GUI_FRIENDLIST_SPLITTER>"
info += "\n" + "<img src=rdb://" + str(
self.profs.get(i.profession)) + "><tab><green>%s<end>\n" % i.profession
info += "\n" + f"<img src=rdb://{self.profs.get(i.profession)}><tab><green>{i.profession}<end>\n"
info += "<img src=tdb://id:GFX_GUI_FRIENDLIST_SPLITTER>"
prof = i.profession
if self.ban.get_ban(i.char_id):
continue
if i.raid_spam == 1:
self.bot.send_mass_message(i.char_id, spam if i.subtile_spam == 0 else subtile)
# if i.raid_invite == 1:
@@ -211,7 +217,7 @@ class RaidController:
self.raid.last_action = time.time()
self.raid.last_spam = time.time()
self.bot.send_mass_message(request.sender.char_id,
f"Successfully sent {len(players)} invites! [{self.text.format_page('More', info)}]")
f"Successfully sent {count} invite{'s' if count != 1 else ''}! [{self.text.format_page('More', info)}]")
@command(command="raid", params=[Const("settings")],
description="Change the title of the Raid", access_level="leader")