Make IRC functions/slots snake_case

This commit is contained in:
Dpeta 2023-02-12 01:12:42 +01:00
parent 8d91b18369
commit 1157e49d9e
No known key found for this signature in database
GPG key ID: 51227517CEA0030C
2 changed files with 69 additions and 69 deletions

90
irc.py
View file

@ -129,16 +129,16 @@ class PesterIRC(QtCore.QThread):
This function reimplements QThread::run() and is ran after self.irc.start() This function reimplements QThread::run() and is ran after self.irc.start()
is called on the main thread. Returning from this method ends the thread.""" is called on the main thread. Returning from this method ends the thread."""
try: try:
self.IRCConnect() self.irc_connect()
except OSError as se: except OSError as se:
self.stopIRC = se self.stopIRC = se
return return
while True: while True:
res = True res = True
try: try:
PchumLog.debug("updateIRC()") PchumLog.debug("update_irc()")
self.mainwindow.sincerecv = 0 self.mainwindow.sincerecv = 0
res = self.updateIRC() res = self.update_irc()
except socket.timeout as se: except socket.timeout as se:
PchumLog.debug("timeout in thread %s", self) PchumLog.debug("timeout in thread %s", self)
self._close() self._close()
@ -261,7 +261,7 @@ class PesterIRC(QtCore.QThread):
except OSError as e: except OSError as e:
PchumLog.info("Error while closing socket, already broken? %s", e) PchumLog.info("Error while closing socket, already broken? %s", e)
def IRCConnect(self): def irc_connect(self):
"""Try to connect and signal for connect-anyway prompt on cert fail.""" """Try to connect and signal for connect-anyway prompt on cert fail."""
try: try:
self._connect(self.verify_hostname) self._connect(self.verify_hostname)
@ -277,7 +277,7 @@ class PesterIRC(QtCore.QThread):
self.disconnectIRC() self.disconnectIRC()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateIRC(self): def update_irc(self):
"""Get a silly scrunkler from the generator!!""" """Get a silly scrunkler from the generator!!"""
try: try:
res = next(self._conn) res = next(self._conn)
@ -293,7 +293,7 @@ class PesterIRC(QtCore.QThread):
return res return res
@QtCore.pyqtSlot(PesterProfile) @QtCore.pyqtSlot(PesterProfile)
def getMood(self, *chums): def get_mood(self, *chums):
"""Get mood via metadata if supported""" """Get mood via metadata if supported"""
# Get via metadata or via legacy method # Get via metadata or via legacy method
@ -308,9 +308,9 @@ class PesterIRC(QtCore.QThread):
else: else:
# Legacy # Legacy
PchumLog.warning( PchumLog.warning(
"Server doesn't seem to support metadata, using legacy GETMOOD." "Server doesn't seem to support metadata, using legacy get_mood."
) )
chumglub = "GETMOOD " chumglub = "get_mood "
for chum in chums: for chum in chums:
if len(chumglub + chum.handle) >= 350: if len(chumglub + chum.handle) >= 350:
try: try:
@ -318,11 +318,11 @@ class PesterIRC(QtCore.QThread):
except OSError as e: except OSError as e:
PchumLog.warning(e) PchumLog.warning(e)
self.setConnectionBroken() self.setConnectionBroken()
chumglub = "GETMOOD " chumglub = "get_mood "
# No point in GETMOOD-ing services # No point in get_mood-ing services
if chum.handle.casefold() not in SERVICES: if chum.handle.casefold() not in SERVICES:
chumglub += chum.handle chumglub += chum.handle
if chumglub != "GETMOOD ": if chumglub != "get_mood ":
try: try:
self._send_irc.privmsg("#pesterchum", chumglub) self._send_irc.privmsg("#pesterchum", chumglub)
except OSError as e: except OSError as e:
@ -330,17 +330,17 @@ class PesterIRC(QtCore.QThread):
self.setConnectionBroken() self.setConnectionBroken()
@QtCore.pyqtSlot(PesterList) @QtCore.pyqtSlot(PesterList)
def getMoods(self, chums): def get_moods(self, chums):
"""Get mood, slot is called from main thread.""" """Get mood, slot is called from main thread."""
self.getMood(*chums) self.get_mood(*chums)
@QtCore.pyqtSlot(str, str) @QtCore.pyqtSlot(str, str)
def sendNotice(self, text, handle): def send_notice(self, text, handle):
"""Send notice, slot is called from main thread.""" """Send notice, slot is called from main thread."""
self._send_irc.notice(handle, text) self._send_irc.notice(handle, text)
@QtCore.pyqtSlot(str, str) @QtCore.pyqtSlot(str, str)
def sendMessage(self, text, handle): def send_message(self, text, handle):
"""......sends a message? this is a tad silly;;;""" """......sends a message? this is a tad silly;;;"""
textl = [text] textl = [text]
@ -386,24 +386,24 @@ class PesterIRC(QtCore.QThread):
self._send_irc.privmsg(handle, t) self._send_irc.privmsg(handle, t)
@QtCore.pyqtSlot(str, str) @QtCore.pyqtSlot(str, str)
def sendCTCP(self, handle, text): def send_ctcp(self, handle, text):
"""Send CTCP message, slot is called from main thread.""" """Send CTCP message, slot is called from main thread."""
self._send_irc.ctcp(handle, text) self._send_irc.ctcp(handle, text)
@QtCore.pyqtSlot(str, bool) @QtCore.pyqtSlot(str, bool)
def startConvo(self, handle, initiated): def start_convo(self, handle, initiated):
"""Send convo begin message and color, slot is called from main thread.""" """Send convo begin message and color, slot is called from main thread."""
self._send_irc.privmsg(handle, f"COLOR >{self.mainwindow.profile().colorcmd()}") self._send_irc.privmsg(handle, f"COLOR >{self.mainwindow.profile().colorcmd()}")
if initiated: if initiated:
self._send_irc.privmsg(handle, "PESTERCHUM:BEGIN") self._send_irc.privmsg(handle, "PESTERCHUM:BEGIN")
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def endConvo(self, handle): def end_convo(self, handle):
"""Send convo cease message, slot is called from main thread.""" """Send convo cease message, slot is called from main thread."""
self._send_irc.privmsg(handle, "PESTERCHUM:CEASE") self._send_irc.privmsg(handle, "PESTERCHUM:CEASE")
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateProfile(self): def update_profile(self):
"""....update profile? this shouldn't be a thing.""" """....update profile? this shouldn't be a thing."""
self._send_irc.nick(self.mainwindow.profile().handle) self._send_irc.nick(self.mainwindow.profile().handle)
self.mainwindow.closeConversations(True) self.mainwindow.closeConversations(True)
@ -413,7 +413,7 @@ class PesterIRC(QtCore.QThread):
self.updateMood() self.updateMood()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateMood(self): def update_mood(self):
"""Update and send mood, slot is called from main thread.""" """Update and send mood, slot is called from main thread."""
mood = self.mainwindow.profile().mood.value_str() mood = self.mainwindow.profile().mood.value_str()
# Moods via metadata # Moods via metadata
@ -422,7 +422,7 @@ class PesterIRC(QtCore.QThread):
self._send_irc.privmsg("#pesterchum", f"MOOD >{mood}") self._send_irc.privmsg("#pesterchum", f"MOOD >{mood}")
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateColor(self): def update_color(self):
"""Update and send color, slot is called from main thread.""" """Update and send color, slot is called from main thread."""
# Update color metadata field # Update color metadata field
color = self.mainwindow.profile().color color = self.mainwindow.profile().color
@ -435,63 +435,63 @@ class PesterIRC(QtCore.QThread):
) )
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def blockedChum(self, handle): def blocked_chum(self, handle):
"""Send block message, slot is called from main thread.""" """Send block message, slot is called from main thread."""
self._send_irc.privmsg(handle, "PESTERCHUM:BLOCK") self._send_irc.privmsg(handle, "PESTERCHUM:BLOCK")
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def unblockedChum(self, handle): def unblocked_chum(self, handle):
"""Send unblock message, slot is called from main thread.""" """Send unblock message, slot is called from main thread."""
self._send_irc.privmsg(handle, "PESTERCHUM:UNBLOCK") self._send_irc.privmsg(handle, "PESTERCHUM:UNBLOCK")
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def requestNames(self, channel): def request_names(self, channel):
"""Send NAMES to request channel members, slot is called from main thread.""" """Send NAMES to request channel members, slot is called from main thread."""
self._send_irc.names(channel) self._send_irc.names(channel)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def requestChannelList(self): def request_channel_list(self):
"""Send LIST to request list of channels, slot is called from main thread.""" """Send LIST to request list of channels, slot is called from main thread."""
self._send_irc.list() self._send_irc.list()
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def joinChannel(self, channel): def join_channel(self, channel):
"""Send JOIN and MODE to join channel and get modes, slot is called from main thread.""" """Send JOIN and MODE to join channel and get modes, slot is called from main thread."""
self._send_irc.join(channel) self._send_irc.join(channel)
self._send_irc.mode(channel) self._send_irc.mode(channel)
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def leftChannel(self, channel): def left_channel(self, channel):
"""Send PART to leave channel, slot is called from main thread.""" """Send PART to leave channel, slot is called from main thread."""
self._send_irc.part(channel) self._send_irc.part(channel)
@QtCore.pyqtSlot(str, str, str) @QtCore.pyqtSlot(str, str, str)
def kickUser(self, channel, user, reason=""): def kick_user(self, channel, user, reason=""):
"""Send KICK message to kick user from channel, slot is called from main thread.""" """Send KICK message to kick user from channel, slot is called from main thread."""
self._send_irc.kick(channel, user, reason) self._send_irc.kick(channel, user, reason)
@QtCore.pyqtSlot(str, str, str) @QtCore.pyqtSlot(str, str, str)
def setChannelMode(self, channel, mode, command): def set_channel_mode(self, channel, mode, command):
"""Send MODE to set channel mode, slot is called from main thread.""" """Send MODE to set channel mode, slot is called from main thread."""
self._send_irc.mode(channel, mode, command) self._send_irc.mode(channel, mode, command)
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def channelNames(self, channel): def channel_names(self, channel):
"""Send block message, slot is called from main thread.""" """Send block message, slot is called from main thread."""
self._send_irc.names(channel) self._send_irc.names(channel)
@QtCore.pyqtSlot(str, str) @QtCore.pyqtSlot(str, str)
def inviteChum(self, handle, channel): def invite_chum(self, handle, channel):
"""Send INVITE message to invite someone to a channel, slot is called from main thread.""" """Send INVITE message to invite someone to a channel, slot is called from main thread."""
self._send_irc.invite(handle, channel) self._send_irc.invite(handle, channel)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def pingServer(self): def ping_server(self):
"""Send PING to server to verify connectivity, slot is called from main thread.""" """Send PING to server to verify connectivity, slot is called from main thread."""
self._send_irc.ping("B33") self._send_irc.ping("B33")
@QtCore.pyqtSlot(bool) @QtCore.pyqtSlot(bool)
def setAway(self, away=True): def set_away(self, away=True):
"""Send AWAY to update away status, slot is called from main thread.""" """Send AWAY to update away status, slot is called from main thread."""
if away: if away:
self.away("Idle") self.away("Idle")
@ -499,12 +499,12 @@ class PesterIRC(QtCore.QThread):
self.away() self.away()
@QtCore.pyqtSlot(str, str) @QtCore.pyqtSlot(str, str)
def killSomeQuirks(self, channel, handle): def kill_some_quirks(self, channel, handle):
"""Send NOQUIRKS ctcp message, disables quirks. Slot is called from main thread.""" """Send NOQUIRKS ctcp message, disables quirks. Slot is called from main thread."""
self._send_irc.ctcp(channel, "NOQUIRKS", handle) self._send_irc.ctcp(channel, "NOQUIRKS", handle)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def disconnectIRC(self): def disconnect_irc(self):
"""Send QUIT and close connection, slot is called from main thread.""" """Send QUIT and close connection, slot is called from main thread."""
self._send_irc.quit(f"{_pcVersion} <3") self._send_irc.quit(f"{_pcVersion} <3")
self._end = True self._end = True
@ -659,7 +659,7 @@ class PesterIRC(QtCore.QThread):
) )
mood = Mood(0) mood = Mood(0)
self.moodUpdated.emit(handle, mood) self.moodUpdated.emit(handle, mood)
elif msg.startswith("GETMOOD"): elif msg.startswith("get_mood"):
mychumhandle = self.mainwindow.profile().handle mychumhandle = self.mainwindow.profile().handle
if mychumhandle in msg: if mychumhandle in msg:
mymood = self.mainwindow.profile().mood.value_str() mymood = self.mainwindow.profile().mood.value_str()
@ -797,7 +797,7 @@ class PesterIRC(QtCore.QThread):
self.moodUpdated.emit(oldhandle, Mood("offline")) self.moodUpdated.emit(oldhandle, Mood("offline"))
self.userPresentUpdate.emit(f"{oldhandle}:{newnick}", "", "nick") self.userPresentUpdate.emit(f"{oldhandle}:{newnick}", "", "nick")
if newnick in self.mainwindow.chumList.chums: if newnick in self.mainwindow.chumList.chums:
self.getMood(newchum) self.get_mood(newchum)
if oldhandle == self.mainwindow.randhandler.randNick: if oldhandle == self.mainwindow.randhandler.randNick:
self.mainwindow.randhandler.setRunning(False) self.mainwindow.randhandler.setRunning(False)
elif newnick == self.mainwindow.randhandler.randNick: elif newnick == self.mainwindow.randhandler.randNick:
@ -912,7 +912,7 @@ class PesterIRC(QtCore.QThread):
for chum in chums: for chum in chums:
if chum.handle in namelist: if chum.handle in namelist:
lesschums.append(chum) lesschums.append(chum)
self.getMood(*lesschums) self.get_mood(*lesschums)
def _cannotsendtochan(self, _server, _handle, channel, msg): def _cannotsendtochan(self, _server, _handle, channel, msg):
"""Numeric reply 404 ERR_CANNOTSENDTOCHAN, we aren't in the channel or don't have voice.""" """Numeric reply 404 ERR_CANNOTSENDTOCHAN, we aren't in the channel or don't have voice."""
@ -972,24 +972,24 @@ class PesterIRC(QtCore.QThread):
def _nomatchingkey(self, _target, _our_handle, failed_handle, _key, *_error): def _nomatchingkey(self, _target, _our_handle, failed_handle, _key, *_error):
"""METADATA DRAFT numeric reply 766 ERR_NOMATCHINGKEY, no matching key.""" """METADATA DRAFT numeric reply 766 ERR_NOMATCHINGKEY, no matching key."""
PchumLog.info("_nomatchingkey: %s", failed_handle) PchumLog.info("_nomatchingkey: %s", failed_handle)
# No point in GETMOOD-ing services # No point in get_mood-ing services
# Fallback to the normal GETMOOD method if getting mood via metadata fails. # Fallback to the normal get_mood method if getting mood via metadata fails.
if failed_handle.casefold() not in SERVICES: if failed_handle.casefold() not in SERVICES:
self._send_irc.privmsg("#pesterchum", f"GETMOOD {failed_handle}") self._send_irc.privmsg("#pesterchum", f"get_mood {failed_handle}")
def _keynotset(self, _target, _our_handle, failed_handle, _key, *_error): def _keynotset(self, _target, _our_handle, failed_handle, _key, *_error):
"""METADATA DRAFT numeric reply 768 ERR_KEYNOTSET, key isn't set.""" """METADATA DRAFT numeric reply 768 ERR_KEYNOTSET, key isn't set."""
PchumLog.info("_keynotset: %s", failed_handle) PchumLog.info("_keynotset: %s", failed_handle)
# Fallback to the normal GETMOOD method if getting mood via metadata fails. # Fallback to the normal get_mood method if getting mood via metadata fails.
if failed_handle.casefold() not in SERVICES: if failed_handle.casefold() not in SERVICES:
self._send_irc.privmsg("#pesterchum", f"GETMOOD {failed_handle}") self._send_irc.privmsg("#pesterchum", f"get_mood {failed_handle}")
def _keynopermission(self, _target, _our_handle, failed_handle, _key, *_error): def _keynopermission(self, _target, _our_handle, failed_handle, _key, *_error):
"""METADATA DRAFT numeric reply 769 ERR_KEYNOPERMISSION, no permission for key.""" """METADATA DRAFT numeric reply 769 ERR_KEYNOPERMISSION, no permission for key."""
PchumLog.info("_keynopermission: %s", failed_handle) PchumLog.info("_keynopermission: %s", failed_handle)
# Fallback to the normal GETMOOD method if getting mood via metadata fails. # Fallback to the normal get_mood method if getting mood via metadata fails.
if failed_handle.casefold() not in SERVICES: if failed_handle.casefold() not in SERVICES:
self._send_irc.privmsg("#pesterchum", f"GETMOOD {failed_handle}") self._send_irc.privmsg("#pesterchum", f"get_mood {failed_handle}")
def _metadatasubok(self, *params): def _metadatasubok(self, *params):
""" "METADATA DRAFT numeric reply 770 RPL_METADATASUBOK, we subbed to a key.""" """ "METADATA DRAFT numeric reply 770 RPL_METADATASUBOK, we subbed to a key."""

View file

@ -4371,30 +4371,30 @@ class MainProgram(QtCore.QObject):
def ircQtConnections(self, irc, widget): def ircQtConnections(self, irc, widget):
# IRC --> Main window # IRC --> Main window
return ( return (
(widget.sendMessage, irc.sendMessage), (widget.sendMessage, irc.send_message),
(widget.sendNotice, irc.sendNotice), (widget.sendNotice, irc.send_notice),
(widget.sendCTCP, irc.sendCTCP), (widget.sendCTCP, irc.send_ctcp),
(widget.newConvoStarted, irc.startConvo), (widget.newConvoStarted, irc.start_convo),
(widget.convoClosed, irc.endConvo), (widget.convoClosed, irc.end_convo),
(widget.profileChanged, irc.updateProfile), (widget.profileChanged, irc.update_profile),
(widget.moodRequest, irc.getMood), (widget.moodRequest, irc.get_mood),
(widget.moodsRequest, irc.getMoods), (widget.moodsRequest, irc.get_moods),
(widget.moodUpdated, irc.updateMood), (widget.moodUpdated, irc.update_mood),
(widget.mycolorUpdated, irc.updateColor), (widget.mycolorUpdated, irc.update_color),
(widget.blockedChum, irc.blockedChum), (widget.blockedChum, irc.blocked_chum),
(widget.unblockedChum, irc.unblockedChum), (widget.unblockedChum, irc.unblocked_chum),
(widget.requestNames, irc.requestNames), (widget.requestNames, irc.request_names),
(widget.requestChannelList, irc.requestChannelList), (widget.requestChannelList, irc.request_channel_list),
(widget.joinChannel, irc.joinChannel), (widget.joinChannel, irc.join_channel),
(widget.leftChannel, irc.leftChannel), (widget.leftChannel, irc.left_channel),
(widget.kickUser, irc.kickUser), (widget.kickUser, irc.kick_user),
(widget.setChannelMode, irc.setChannelMode), (widget.setChannelMode, irc.set_channel_mode),
(widget.channelNames, irc.channelNames), (widget.channelNames, irc.channel_names),
(widget.inviteChum, irc.inviteChum), (widget.inviteChum, irc.invite_chum),
(widget.pingServer, irc.pingServer), (widget.pingServer, irc.ping_server),
(widget.setAway, irc.setAway), (widget.setAway, irc.set_away),
(widget.killSomeQuirks, irc.killSomeQuirks), (widget.killSomeQuirks, irc.kill_some_quirks),
(widget.disconnectIRC, irc.disconnectIRC), (widget.disconnectIRC, irc.disconnect_irc),
# Main window --> IRC # Main window --> IRC
(irc.connected, widget.connected), (irc.connected, widget.connected),
(irc.askToConnect, widget.connectAnyway), (irc.askToConnect, widget.connectAnyway),