polls get sent to all members on logon
dirty fix for the MA nanolines There's an error with the urllib, downgrading the dependency.
This commit is contained in:
@@ -305,10 +305,23 @@ class AccountService:
|
||||
return ["success", True]
|
||||
|
||||
def get_orgs(self) -> list:
|
||||
try:
|
||||
return [x["org_id"] for x in self.db.query("SELECT * from orgs", [])]
|
||||
except SqlException:
|
||||
return [self.bot.public_channel_service.org_id]
|
||||
# With the broader usage of the "simple_checks" (Check for ban, org membership, ....)
|
||||
# We might need to cache the orgs matching the filters.
|
||||
# As these dont change as frequently as the account [if at all],
|
||||
# Saving them for longer should be safe.
|
||||
if not hasattr(self, "orgs"):
|
||||
try:
|
||||
def del_orgs(_):
|
||||
del self.orgs
|
||||
self.orgs = [x["org_id"] for x in self.db.query("SELECT * from orgs", [])]
|
||||
self.bot.job_scheduler.delayed_job(del_orgs, 60)
|
||||
return self.orgs
|
||||
# The table "orgs" does not exist, which means the bot is not running the onlinebot modules.
|
||||
# Cache lifetime is infinity, as the bot usually wont leave its org while its online.
|
||||
except SqlException:
|
||||
self.orgs = [self.bot.public_channel_service.org_id]
|
||||
return self.orgs
|
||||
return self.orgs
|
||||
|
||||
def create_users(self, users, disable=False) -> int:
|
||||
# Default preferences
|
||||
@@ -530,6 +543,8 @@ class AccountService:
|
||||
points = -points
|
||||
self.db.exec("UPDATE account set points = points-? where char_id=(select main from account where char_id=?)",
|
||||
[points, char_id])
|
||||
if account := self.acc_cache.get(char_id, None):
|
||||
account.points -= points
|
||||
self.add_log(char_id, 'points', reason, leader, delta=-points)
|
||||
|
||||
def add_rank(self, char_id, rank) -> int:
|
||||
|
||||
@@ -158,8 +158,11 @@ class NanoController:
|
||||
|
||||
@command(command="nanolines", params=[Any("profession"), Any("nanoline")], access_level="member",
|
||||
description="Show nanos by nanoline profession and line name")
|
||||
def nanolines_prof_strain(self, _, prof, strain):
|
||||
def nanolines_prof_strain(self, _, prof: str, strain: str):
|
||||
profession = self.util.get_profession(prof)
|
||||
if strain.startswith("Artist"):
|
||||
profession = "Martial Artist"
|
||||
strain = strain[7:]
|
||||
nanoline = self.db.query_single(
|
||||
"SELECT * FROM nanos n WHERE n.strain LIKE ? AND profession =? and type='Crystal' LIMIT 1",
|
||||
[strain, profession])
|
||||
|
||||
@@ -3,7 +3,7 @@ import time
|
||||
from core.chat_blob import ChatBlob
|
||||
from core.command_param_types import Const, Any, Int
|
||||
from core.decorators import instance, command, event
|
||||
from modules.orgbot.org.org_roster_controller import OrgRosterController
|
||||
from modules.core.accounting.services.account_service import AccountService
|
||||
|
||||
|
||||
@instance()
|
||||
@@ -16,7 +16,7 @@ class PollController:
|
||||
self.job_scheduler = registry.get_instance("job_scheduler")
|
||||
self.pork_service = registry.get_instance("pork_service")
|
||||
self.command_alias_service = registry.get_instance("command_alias_service")
|
||||
self.account_service = registry.get_instance("account_service")
|
||||
self.account_service: AccountService = registry.get_instance("account_service")
|
||||
|
||||
def start(self):
|
||||
self.db.exec("CREATE TABLE IF NOT EXISTS poll ("
|
||||
@@ -155,16 +155,20 @@ class PollController:
|
||||
self.check_for_finished_polls()
|
||||
self.create_scheduled_jobs_for_polls()
|
||||
|
||||
@event(event_type=OrgRosterController.ORG_MEMBER_LOGON_EVENT,
|
||||
@event(event_type="member_logon",
|
||||
description="Send active polls to org members logging on")
|
||||
def org_member_logon_event(self, event_type, event_data):
|
||||
def poll_on_logon(self, event_type, event_data):
|
||||
if self.bot.is_ready():
|
||||
data = self.db.query("SELECT * FROM poll WHERE is_finished != 1 AND "
|
||||
"id NOT IN (SELECT poll_id FROM poll_vote WHERE char_id = ?) "
|
||||
"ORDER BY finished_at, id", [event_data.account.char_id])
|
||||
if data:
|
||||
row = data[0]
|
||||
self.bot.send_private_message(event_data.char_id, self.show_poll_details_blob(row))
|
||||
# Only proceed if the "normal" checks are fine
|
||||
if not self.account_service.simple_checks(event_data.account):
|
||||
return
|
||||
if event_data.account.news_spam == 1:
|
||||
data = self.db.query("SELECT * FROM poll WHERE is_finished != 1 AND "
|
||||
"id NOT IN (SELECT poll_id FROM poll_vote WHERE char_id = ?) "
|
||||
"ORDER BY finished_at, id", [event_data.account.char_id])
|
||||
if data:
|
||||
row = data[0]
|
||||
self.bot.send_private_message(event_data.char_info.char_id, self.show_poll_details_blob(row))
|
||||
|
||||
def create_scheduled_jobs_for_polls(self):
|
||||
data = self.db.query("SELECT * FROM poll WHERE is_finished != 1")
|
||||
|
||||
@@ -14,3 +14,4 @@ websock~=1.0.4
|
||||
pip>=21.2.4
|
||||
websockets~=9.1
|
||||
torpy~=1.1.6
|
||||
urllib3==1.25.11
|
||||
|
||||
Reference in New Issue
Block a user