mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-24 11:42:51 +01:00
everything: Improve logging
This commit is contained in:
parent
54dff7a15a
commit
211decd2aa
6
main.py
6
main.py
@ -83,12 +83,12 @@ class Irc():
|
|||||||
log.error('Failed to load plugin %r: the plugin could not be found.', plugin)
|
log.error('Failed to load plugin %r: the plugin could not be found.', plugin)
|
||||||
else:
|
else:
|
||||||
log.error('Failed to load plugin %r: import error %s', plugin, str(e))
|
log.error('Failed to load plugin %r: import error %s', plugin, str(e))
|
||||||
print("loaded plugins: %s" % self.loaded)
|
log.info("loaded plugins: %s", self.loaded)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print('PyLink starting...')
|
log.info('PyLink starting...')
|
||||||
if conf['login']['password'] == 'changeme':
|
if conf['login']['password'] == 'changeme':
|
||||||
print("You have not set the login details correctly! Exiting...")
|
log.critical("You have not set the login details correctly! Exiting...")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
protoname = conf['server']['protocol']
|
protoname = conf['server']['protocol']
|
||||||
|
@ -6,12 +6,13 @@ import logging
|
|||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
import utils
|
import utils
|
||||||
from conf import conf
|
from conf import conf
|
||||||
|
from log import log
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def debug(irc, source, args):
|
def debug(irc, source, args):
|
||||||
print('user index: %s' % irc.users)
|
log.debug('user index: %s' % irc.users)
|
||||||
print('server index: %s' % irc.servers)
|
log.debug('server index: %s' % irc.servers)
|
||||||
print('channels index: %s' % irc.channels)
|
log.debug('channels index: %s' % irc.channels)
|
||||||
utils.msg(irc, source, 'Debug info printed to console.')
|
utils.msg(irc, source, 'Debug info printed to console.')
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
import sys, os
|
import sys, os
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
import utils
|
import utils
|
||||||
|
from log import log
|
||||||
|
|
||||||
def hook_join(irc, source, command, args):
|
def hook_join(irc, source, command, args):
|
||||||
channel = args['channel']
|
channel = args['channel']
|
||||||
users = args['users']
|
users = args['users']
|
||||||
print('%s joined channel %s (JOIN hook caught)' % (users, channel))
|
log.info('%s joined channel %s (JOIN hook caught)' % (users, channel))
|
||||||
utils.add_hook(hook_join, 'JOIN')
|
utils.add_hook(hook_join, 'JOIN')
|
||||||
|
|
||||||
def hook_privmsg(irc, source, command, args):
|
def hook_privmsg(irc, source, command, args):
|
||||||
@ -14,5 +15,5 @@ def hook_privmsg(irc, source, command, args):
|
|||||||
text = args['text']
|
text = args['text']
|
||||||
if utils.isChannel(channel) and irc.pseudoclient.nick in text:
|
if utils.isChannel(channel) and irc.pseudoclient.nick in text:
|
||||||
utils.msg(irc, channel, 'hi there!')
|
utils.msg(irc, channel, 'hi there!')
|
||||||
print('%s said my name on channel %s (PRIVMSG hook caught)' % (source, channel))
|
log.info('%s said my name on channel %s (PRIVMSG hook caught)' % (source, channel))
|
||||||
utils.add_hook(hook_privmsg, 'PRIVMSG')
|
utils.add_hook(hook_privmsg, 'PRIVMSG')
|
||||||
|
@ -417,11 +417,11 @@ def handle_events(irc, data):
|
|||||||
hook_cmd = command
|
hook_cmd = command
|
||||||
if command in hook_map:
|
if command in hook_map:
|
||||||
hook_cmd = hook_map[command]
|
hook_cmd = hook_map[command]
|
||||||
print('Parsed args %r received from %s handler (calling hook %s)' % (parsed_args, command, hook_cmd))
|
log.debug('Parsed args %r received from %s handler (calling hook %s)', parsed_args, command, hook_cmd)
|
||||||
# Iterate over hooked functions, catching errors accordingly
|
# Iterate over hooked functions, catching errors accordingly
|
||||||
for hook_func in utils.command_hooks[hook_cmd]:
|
for hook_func in utils.command_hooks[hook_cmd]:
|
||||||
try:
|
try:
|
||||||
print('Calling function %s' % hook_func)
|
log.debug('Calling function %s', hook_func)
|
||||||
hook_func(irc, numeric, command, parsed_args)
|
hook_func(irc, numeric, command, parsed_args)
|
||||||
except Exception:
|
except Exception:
|
||||||
# We don't want plugins to crash our servers...
|
# We don't want plugins to crash our servers...
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
from log import log
|
||||||
|
|
||||||
import main
|
import main
|
||||||
import classes
|
import classes
|
||||||
@ -35,12 +36,12 @@ class FakeIRC(main.Irc):
|
|||||||
|
|
||||||
def run(self, data):
|
def run(self, data):
|
||||||
"""Queues a message to the fake IRC server."""
|
"""Queues a message to the fake IRC server."""
|
||||||
print('-> ' + data)
|
log.debug('-> ' + data)
|
||||||
self.proto.handle_events(self, data)
|
self.proto.handle_events(self, data)
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
self.messages.append(data)
|
self.messages.append(data)
|
||||||
print('<- ' + data)
|
log.debug('<- ' + data)
|
||||||
|
|
||||||
def takeMsgs(self):
|
def takeMsgs(self):
|
||||||
"""Returns a list of messages sent by the protocol module since
|
"""Returns a list of messages sent by the protocol module since
|
||||||
|
35
utils.py
35
utils.py
@ -2,6 +2,8 @@ import string
|
|||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from log import log
|
||||||
|
|
||||||
global bot_commands, command_hooks
|
global bot_commands, command_hooks
|
||||||
# This should be a mapping of command names to functions
|
# This should be a mapping of command names to functions
|
||||||
bot_commands = {}
|
bot_commands = {}
|
||||||
@ -98,13 +100,12 @@ def parseModes(irc, target, args):
|
|||||||
return ValueError('No modes supplied in parseModes query: %r' % modes)
|
return ValueError('No modes supplied in parseModes query: %r' % modes)
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
if usermodes:
|
if usermodes:
|
||||||
|
log.debug('Using irc.umodes for this query: %s', irc.umodes)
|
||||||
supported_modes = irc.umodes
|
supported_modes = irc.umodes
|
||||||
else:
|
else:
|
||||||
|
log.debug('Using irc.cmodes for this query: %s', irc.cmodes)
|
||||||
supported_modes = irc.cmodes
|
supported_modes = irc.cmodes
|
||||||
print('supported modes: %s' % supported_modes)
|
|
||||||
res = []
|
res = []
|
||||||
for x in ('A', 'B', 'C', 'D'):
|
|
||||||
print('%s modes: %s' % (x, supported_modes['*'+x]))
|
|
||||||
for mode in modestring:
|
for mode in modestring:
|
||||||
if mode in '+-':
|
if mode in '+-':
|
||||||
prefix = mode
|
prefix = mode
|
||||||
@ -112,62 +113,54 @@ def parseModes(irc, target, args):
|
|||||||
arg = None
|
arg = None
|
||||||
if mode in (supported_modes['*A'] + supported_modes['*B']):
|
if mode in (supported_modes['*A'] + supported_modes['*B']):
|
||||||
# Must have parameter.
|
# Must have parameter.
|
||||||
print('%s: Must have parameter.' % mode)
|
log.debug('%s: This mode must have parameter.', mode)
|
||||||
arg = args.pop(0)
|
arg = args.pop(0)
|
||||||
elif mode in irc.prefixmodes and not usermodes:
|
elif mode in irc.prefixmodes and not usermodes:
|
||||||
# We're setting a prefix mode on someone (e.g. +o user1)
|
# We're setting a prefix mode on someone (e.g. +o user1)
|
||||||
print('%s: prefixmode.' % mode)
|
log.debug('%s: This mode is a prefix mode.', mode)
|
||||||
arg = args.pop(0)
|
arg = args.pop(0)
|
||||||
elif prefix == '+' and mode in supported_modes['*C']:
|
elif prefix == '+' and mode in supported_modes['*C']:
|
||||||
# Only has parameter when setting.
|
# Only has parameter when setting.
|
||||||
print('%s: Only has parameter when setting.' % mode)
|
log.debug('%s: Only has parameter when setting.', mode)
|
||||||
arg = args.pop(0)
|
arg = args.pop(0)
|
||||||
res.append((prefix + mode, arg))
|
res.append((prefix + mode, arg))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def applyModes(irc, target, changedmodes):
|
def applyModes(irc, target, changedmodes):
|
||||||
usermodes = not isChannel(target)
|
usermodes = not isChannel(target)
|
||||||
print('usermodes? %s' % usermodes)
|
log.debug('usermodes? %s' % usermodes)
|
||||||
if usermodes:
|
if usermodes:
|
||||||
modelist = irc.users[target].modes
|
modelist = irc.users[target].modes
|
||||||
else:
|
else:
|
||||||
modelist = irc.channels[target].modes
|
modelist = irc.channels[target].modes
|
||||||
print('Initial modelist: %s' % modelist)
|
log.debug('(%s) Applying modes %r on %s (initial modelist: %s)', irc.name, changedmodes, target, modelist)
|
||||||
print('Changedmodes: %r' % changedmodes)
|
|
||||||
for mode in changedmodes:
|
for mode in changedmodes:
|
||||||
if not usermodes:
|
if not usermodes:
|
||||||
pmode = ''
|
pmode = ''
|
||||||
for m in ('owner', 'admin', 'op', 'halfop', 'voice'):
|
for m in ('owner', 'admin', 'op', 'halfop', 'voice'):
|
||||||
if m in irc.cmodes and mode[0][1] == irc.cmodes[m]:
|
if m in irc.cmodes and mode[0][1] == irc.cmodes[m]:
|
||||||
pmode = m+'s'
|
pmode = m+'s'
|
||||||
print('pmode? %s' % pmode)
|
|
||||||
if pmode:
|
if pmode:
|
||||||
print('pmode == True')
|
|
||||||
print(mode)
|
|
||||||
print(irc.channels[target].prefixmodes)
|
|
||||||
pmodelist = irc.channels[target].prefixmodes[pmode]
|
pmodelist = irc.channels[target].prefixmodes[pmode]
|
||||||
print(pmodelist)
|
log.debug('(%s) Initial prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
|
||||||
print('Initial pmodelist: %s' % pmodelist)
|
|
||||||
if mode[0][0] == '+':
|
if mode[0][0] == '+':
|
||||||
pmodelist.add(mode[1])
|
pmodelist.add(mode[1])
|
||||||
print('+')
|
|
||||||
else:
|
else:
|
||||||
pmodelist.discard(mode[1])
|
pmodelist.discard(mode[1])
|
||||||
print('-')
|
log.debug('(%s) Final prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
|
||||||
print('Final pmodelist: %s' % pmodelist)
|
|
||||||
if mode[0][1] in irc.prefixmodes:
|
if mode[0][1] in irc.prefixmodes:
|
||||||
# Ignore other prefix modes such as InspIRCd's +Yy
|
# Ignore other prefix modes such as InspIRCd's +Yy
|
||||||
continue
|
continue
|
||||||
if mode[0][0] == '+':
|
if mode[0][0] == '+':
|
||||||
# We're adding a mode
|
# We're adding a mode
|
||||||
modelist.add(mode)
|
modelist.add(mode)
|
||||||
print('Adding mode %r' % str(mode))
|
log.debug('(%s) Adding mode %r on %s', irc.name, mode, target)
|
||||||
else:
|
else:
|
||||||
# We're removing a mode
|
# We're removing a mode
|
||||||
mode[0] = mode[0].replace('-', '+')
|
mode[0] = mode[0].replace('-', '+')
|
||||||
modelist.discard(mode)
|
modelist.discard(mode)
|
||||||
print('Removing mode %r' % str(mode))
|
log.debug('(%s) Removing mode %r on %s', irc.name, mode, target)
|
||||||
print('Final modelist: %s' % modelist)
|
log.debug('Final modelist: %s' % modelist)
|
||||||
|
|
||||||
def joinModes(modes):
|
def joinModes(modes):
|
||||||
modelist = ''
|
modelist = ''
|
||||||
|
Loading…
Reference in New Issue
Block a user