mirror of
https://github.com/osmarks/autobotrobot
synced 2025-01-09 07:00:27 +00:00
IRC link as extension
This commit is contained in:
parent
fe0918120e
commit
76e04227a7
@ -15,12 +15,18 @@ def color_code(x):
|
|||||||
return f"\x03{x}"
|
return f"\x03{x}"
|
||||||
def random_color(id): return color_code(hashlib.blake2b(str(id).encode("utf-8")).digest()[0] % 13 + 2)
|
def random_color(id): return color_code(hashlib.blake2b(str(id).encode("utf-8")).digest()[0] % 13 + 2)
|
||||||
|
|
||||||
|
global_conn = None
|
||||||
|
|
||||||
async def initialize():
|
async def initialize():
|
||||||
|
logging.info("Initializing IRC link")
|
||||||
|
|
||||||
joined = set()
|
joined = set()
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
reactor = irc.client_aio.AioReactor(loop=loop)
|
reactor = irc.client_aio.AioReactor(loop=loop)
|
||||||
conn = await reactor.server().connect(util.config["irc"]["server"], util.config["irc"]["port"], util.config["irc"]["nick"])
|
conn = await reactor.server().connect(util.config["irc"]["server"], util.config["irc"]["port"], util.config["irc"]["nick"])
|
||||||
|
global global_conn
|
||||||
|
global_conn = conn
|
||||||
|
|
||||||
def inuse(conn, event):
|
def inuse(conn, event):
|
||||||
conn.nick(scramble(conn.get_nickname()))
|
conn.nick(scramble(conn.get_nickname()))
|
||||||
@ -52,3 +58,9 @@ async def initialize():
|
|||||||
conn.add_global_handler("pubmsg", pubmsg)
|
conn.add_global_handler("pubmsg", pubmsg)
|
||||||
|
|
||||||
eventbus.add_listener(util.config["irc"]["name"], on_bridge_message)
|
eventbus.add_listener(util.config["irc"]["name"], on_bridge_message)
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
asyncio.create_task(initialize())
|
||||||
|
|
||||||
|
def teardown(bot):
|
||||||
|
if global_conn: global_conn.disconnect()
|
@ -52,7 +52,8 @@ command_errors = prometheus_client.Counter("abr_errors", "Count of errors encoun
|
|||||||
async def on_command_error(ctx, err):
|
async def on_command_error(ctx, err):
|
||||||
if isinstance(err, (commands.CommandNotFound, commands.CheckFailure)): return
|
if isinstance(err, (commands.CommandNotFound, commands.CheckFailure)): return
|
||||||
if isinstance(err, commands.CommandInvokeError) and isinstance(err.original, ValueError): return await ctx.send(embed=util.error_embed(str(err.original)))
|
if isinstance(err, commands.CommandInvokeError) and isinstance(err.original, ValueError): return await ctx.send(embed=util.error_embed(str(err.original)))
|
||||||
if isinstance(err, commands.MissingRequiredArgument): return await ctx.send(embed=util.error_embed(str(err)))
|
# TODO: really should find a way to detect ALL user errors here?
|
||||||
|
if isinstance(err, (commands.MissingRequiredArgument, commands.ExpectedClosingQuoteError, commands.InvalidEndOfQuotedStringError)): return await ctx.send(embed=util.error_embed(str(err)))
|
||||||
try:
|
try:
|
||||||
command_errors.inc()
|
command_errors.inc()
|
||||||
trace = re.sub("\n\n+", "\n", "\n".join(traceback.format_exception(err, err, err.__traceback__)))
|
trace = re.sub("\n\n+", "\n", "\n".join(traceback.format_exception(err, err, err.__traceback__)))
|
||||||
@ -127,7 +128,6 @@ async def run_bot():
|
|||||||
bot.database = await db.init(config["database"])
|
bot.database = await db.init(config["database"])
|
||||||
await eventbus.initial_load(bot.database)
|
await eventbus.initial_load(bot.database)
|
||||||
await initial_load_webhooks(bot.database)
|
await initial_load_webhooks(bot.database)
|
||||||
await irc_link.initialize()
|
|
||||||
for ext in util.extensions:
|
for ext in util.extensions:
|
||||||
logging.info("loaded %s", ext)
|
logging.info("loaded %s", ext)
|
||||||
bot.load_extension(ext)
|
bot.load_extension(ext)
|
||||||
|
@ -263,7 +263,8 @@ extensions = (
|
|||||||
"heavserver",
|
"heavserver",
|
||||||
"voice",
|
"voice",
|
||||||
"commands",
|
"commands",
|
||||||
"userdata"
|
"userdata",
|
||||||
|
"irc_link"
|
||||||
)
|
)
|
||||||
|
|
||||||
# https://github.com/SawdustSoftware/simpleflake/blob/master/simpleflake/simpleflake.py
|
# https://github.com/SawdustSoftware/simpleflake/blob/master/simpleflake/simpleflake.py
|
||||||
|
Loading…
Reference in New Issue
Block a user