Move services functionality to services.py
This commit is contained in:
parent
db69aecb56
commit
e03060a433
5 changed files with 59 additions and 47 deletions
10
irc.py
10
irc.py
|
@ -47,15 +47,7 @@ from scripts.ssl_context import get_ssl_context
|
|||
from scripts.input_validation import is_valid_mood, is_valid_rgb_color
|
||||
|
||||
PchumLog = logging.getLogger("pchumLogger")
|
||||
SERVICES = [
|
||||
"nickserv",
|
||||
"chanserv",
|
||||
"memoserv",
|
||||
"operserv",
|
||||
"helpserv",
|
||||
"hostserv",
|
||||
"botserv",
|
||||
]
|
||||
from scripts.services import SERVICES
|
||||
|
||||
|
||||
class PesterIRC(QtCore.QThread):
|
||||
|
|
6
memos.py
6
memos.py
|
@ -25,6 +25,7 @@ from parsetools import (
|
|||
smiledict,
|
||||
)
|
||||
from logviewer import PesterLogViewer
|
||||
from scripts.services import BOTNAMES
|
||||
|
||||
PchumLog = logging.getLogger("pchumLogger")
|
||||
_valid_memo_msg_start = re.compile(
|
||||
|
@ -389,7 +390,10 @@ class MemoText(PesterText):
|
|||
window = parent.mainwindow
|
||||
me = window.profile()
|
||||
if isinstance(msg, str):
|
||||
if self.mainwindow.config.force_prefix():
|
||||
if (
|
||||
self.mainwindow.config.force_prefix()
|
||||
and chum.handle.casefold() not in BOTNAMES
|
||||
):
|
||||
msg = self.make_valid(msg, chum, parent, window, me)
|
||||
lexmsg = lexMessage(msg)
|
||||
else:
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
# Hardcoded messages that NickServ sends and what to display to the user instead
|
||||
|
||||
messages = {
|
||||
"Your nick isn't registered.": "", # display the same
|
||||
"Password accepted - you are now recognized.": "", # display the same
|
||||
"If you do not change within one minute, I will change your nick.": "You have 1 minute to identify.",
|
||||
"If you do not change within 20 seconds, I will change your nick.": "You have 20 seconds to identify.",
|
||||
}
|
||||
|
||||
|
||||
def translate(msg):
|
||||
if msg in messages:
|
||||
if messages[msg] == "":
|
||||
return msg
|
||||
return messages[msg]
|
||||
return None
|
|
@ -16,7 +16,6 @@ if os.path.dirname(sys.argv[0]):
|
|||
os.chdir(os.path.dirname(sys.argv[0]))
|
||||
|
||||
import ostools
|
||||
import nickservmsgs
|
||||
import pytwmn
|
||||
|
||||
from user_profile import (
|
||||
|
@ -61,6 +60,7 @@ from irc import PesterIRC
|
|||
from logviewer import PesterLogUserSelect, PesterLogViewer
|
||||
from randomer import RandomHandler, RANDNICK
|
||||
from toast import PesterToastMachine, PesterToast
|
||||
from scripts.services import SERVICES, CUSTOMBOTS, BOTNAMES, translate_nickserv_msg
|
||||
|
||||
try:
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets, QtMultimedia
|
||||
|
@ -133,20 +133,6 @@ stream_handler.setFormatter(formatter)
|
|||
PchumLog.addHandler(file_handler)
|
||||
PchumLog.addHandler(stream_handler)
|
||||
|
||||
# Global variables
|
||||
BOTNAMES = []
|
||||
CUSTOMBOTS = ["CALSPRITE", RANDNICK.upper()]
|
||||
SERVICES = [
|
||||
"NICKSERV",
|
||||
"CHANSERV",
|
||||
"MEMOSERV",
|
||||
"OPERSERV",
|
||||
"HELPSERV",
|
||||
"HOSTSERV",
|
||||
"BOTSERV",
|
||||
]
|
||||
BOTNAMES.extend(CUSTOMBOTS)
|
||||
BOTNAMES.extend(SERVICES)
|
||||
# Command line arguments
|
||||
_ARGUMENTS = parser.parse_args()
|
||||
|
||||
|
@ -1787,7 +1773,7 @@ class PesterWindow(MovingWindow):
|
|||
t.show()
|
||||
elif not self.config.notifyOptions() & self.config.NEWCONVO:
|
||||
if msg[:11] != "PESTERCHUM:":
|
||||
if handle.upper() not in BOTNAMES:
|
||||
if handle.casefold() not in BOTNAMES:
|
||||
t = self.tm.Toast(
|
||||
"From: %s" % handle, re.sub("</?c(=.*?)?>", "", msg)
|
||||
)
|
||||
|
@ -1912,12 +1898,12 @@ class PesterWindow(MovingWindow):
|
|||
convoWindow.messageSent[str, str].connect(self.sendMessage[str, str])
|
||||
convoWindow.windowClosed[str].connect(self.closeConvo)
|
||||
self.convos[chum.handle] = convoWindow
|
||||
if chum.handle.upper() in BOTNAMES:
|
||||
if chum.handle.casefold() in BOTNAMES:
|
||||
convoWindow.toggleQuirks(True)
|
||||
convoWindow.quirksOff.setChecked(True)
|
||||
if (
|
||||
not self.config.irc_compatibility_mode()
|
||||
or chum.handle.upper() in CUSTOMBOTS
|
||||
or chum.handle.casefold() in CUSTOMBOTS
|
||||
):
|
||||
self.newConvoStarted.emit(chum.handle, initiated)
|
||||
else:
|
||||
|
@ -2450,11 +2436,11 @@ class PesterWindow(MovingWindow):
|
|||
elif h in self.convos:
|
||||
self.newMessage(h, m)
|
||||
elif h.upper() == "NICKSERV" and "PESTERCHUM:" not in m:
|
||||
m = nickservmsgs.translate(m)
|
||||
m = translate_nickserv_msg(m)
|
||||
if m:
|
||||
t = self.tm.Toast("NickServ:", m)
|
||||
t.show()
|
||||
elif ("PESTERCHUM:" not in m) and (h.upper() in SERVICES):
|
||||
elif "PESTERCHUM:" not in m and h.casefold() in SERVICES:
|
||||
# Show toast for rest services notices
|
||||
# "Your VHOST is actived", "You have one new memo", etc.
|
||||
t = self.tm.Toast("%s:" % h, m)
|
||||
|
@ -2742,7 +2728,7 @@ class PesterWindow(MovingWindow):
|
|||
# Presented here so it can be called by other scripts.
|
||||
@staticmethod
|
||||
def isBot(handle):
|
||||
return handle.upper() in BOTNAMES
|
||||
return handle.casefold() in BOTNAMES
|
||||
|
||||
@QtCore.pyqtSlot()
|
||||
def showMemos(self, channel=""):
|
||||
|
|
46
scripts/services.py
Normal file
46
scripts/services.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
"""Lists, dicts, and functions related to services."""
|
||||
from randomer import RANDNICK
|
||||
|
||||
# List of all common services bots. (for .casefold() matching)
|
||||
# Services packages that provide the bot are in the same-line comments.
|
||||
SERVICES = [
|
||||
"nickserv", # Anope/Atheme/X3/DalekIRC
|
||||
"chanserv", # Anope/Atheme/X3/DalekIRC
|
||||
"memoserv", # Anope/Atheme
|
||||
"operserv", # Anope/Atheme/DalekIRC
|
||||
"helpserv", # Anope/Atheme/X3
|
||||
"hostserv", # Anope/Atheme
|
||||
"botserv", # Anope/Atheme/DalekIRC
|
||||
"global", # Anope/Atheme/DalekIRC
|
||||
"alis", # Atheme
|
||||
"chanfix", # Atheme
|
||||
"gameserv", # Atheme
|
||||
"groupserv", # Atheme
|
||||
"infoserv", # Atheme
|
||||
"statserv", # Atheme
|
||||
"userserv", # Atheme
|
||||
"authserv", # X3
|
||||
"opserv", # X3
|
||||
"metaserv", # DalekIRC
|
||||
"bbserv", # DalekIRC
|
||||
]
|
||||
# Pesterchum bots
|
||||
CUSTOMBOTS = ["calsprite", RANDNICK.casefold()]
|
||||
# All bots
|
||||
BOTNAMES = SERVICES + CUSTOMBOTS
|
||||
|
||||
# Hardcoded messages that NickServ sends and what to display to the user instead
|
||||
nickserv_messages = {
|
||||
"Your nick isn't registered.": "", # display the same
|
||||
"Password accepted - you are now recognized.": "", # display the same
|
||||
"If you do not change within one minute, I will change your nick.": "You have 1 minute to identify.",
|
||||
"If you do not change within 20 seconds, I will change your nick.": "You have 20 seconds to identify.",
|
||||
}
|
||||
|
||||
|
||||
def translate_nickserv_msg(msg):
|
||||
if msg in nickserv_messages:
|
||||
if not nickserv_messages[msg]: # == "":
|
||||
return msg
|
||||
return nickserv_messages[msg]
|
||||
return None
|
Loading…
Reference in a new issue