Implement src/IRCObject.py to convert specific objects in to strings when

passing them to modules/scripts.py scripts
This commit is contained in:
jesopo 2018-10-01 13:48:55 +01:00
parent 120acf54ec
commit 59243f492f
4 changed files with 13 additions and 7 deletions

View file

@ -1,6 +1,6 @@
import glob, json, os, subprocess
from src import Utils
from src import IRCObject, Utils
class Module(object):
def __init__(self, bot, events, exports):
@ -37,6 +37,8 @@ class Module(object):
env[key.upper()] = str(int(value))
elif isinstance(value, (list, dict)):
env[key.upper()] = json.dumps(value)
elif isinstance(value, (IRCObject.Object,)):
env[key.upper()] = str(value)
proc = subprocess.Popen([filename], stdout=subprocess.PIPE, env=env)
try:

View file

@ -1,7 +1,7 @@
import uuid
from . import IRCBuffer, Utils
from . import IRCBuffer, IRCObject, Utils
class Channel(object):
class Channel(IRCObject.Object):
def __init__(self, name, id, server, bot):
self.name = Utils.irc_lower(server, name)
self.id = id
@ -19,6 +19,8 @@ class Channel(object):
def __repr__(self):
return "IRCChannel.Channel(%s|%s)" % (self.server.name, self.name)
def __str__(self):
return self.name
def set_topic(self, topic):
self.topic = topic

View file

@ -1,12 +1,12 @@
import collections, socket, ssl, sys, time
from . import IRCChannel, IRCUser, Utils
from . import IRCChannel, IRCObject, IRCUser, Utils
THROTTLE_LINES = 4
THROTTLE_SECONDS = 1
READ_TIMEOUT_SECONDS = 120
PING_INTERVAL_SECONDS = 30
class Server(object):
class Server(IRCObject.Object):
def __init__(self, bot, events, id, alias, hostname, port, password,
ipv4, tls, nickname, username, realname):
self.connected = False

View file

@ -1,7 +1,7 @@
import uuid
from . import IRCBuffer, Utils
from . import IRCBuffer, IRCObject, Utils
class User(object):
class User(IRCObject.Object):
def __init__(self, nickname, id, server, bot):
self.server = server
self.set_nickname(nickname)
@ -22,6 +22,8 @@ class User(object):
def __repr__(self):
return "IRCUser.User(%s|%s)" % (self.server.name, self.name)
def __str__(self):
return self.nickname
def get_id(self):
return (self.identified_account_id_override or