2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-05-17 15:14:23 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.changenickname", min_args=1)
|
2016-05-17 15:14:23 +00:00
|
|
|
def change_nickname(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Change my nickname
|
|
|
|
:usage: <nickname>
|
|
|
|
:permission: changenickname
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-05-17 15:14:23 +00:00
|
|
|
nickname = event["args_split"][0]
|
|
|
|
event["server"].send_nick(nickname)
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.raw", min_args=1)
|
2016-05-17 15:14:23 +00:00
|
|
|
def raw(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Send a line of raw IRC data
|
|
|
|
:usage: <raw line>
|
|
|
|
:permission: raw
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-05-17 15:14:23 +00:00
|
|
|
event["server"].send(event["args"])
|
2016-06-24 08:17:27 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.part")
|
2016-06-24 08:17:27 +00:00
|
|
|
def part(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Part from the current or given channel
|
|
|
|
:usage: [channel]
|
|
|
|
:permission: part
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
if event["args"]:
|
|
|
|
target = event["args_split"][0]
|
|
|
|
elif event["is_channel"]:
|
|
|
|
target = event["target"].name
|
|
|
|
else:
|
|
|
|
event["stderr"].write("No channel provided")
|
|
|
|
event["server"].send_part(target)
|
2018-09-03 17:21:13 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.reconnect")
|
2018-09-03 17:21:13 +00:00
|
|
|
def reconnect(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Reconnect to the current network
|
|
|
|
:permission: reconnect
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2019-02-10 14:26:24 +00:00
|
|
|
line = event["server"].send_quit("Reconnecting")
|
|
|
|
line.on_send(lambda: self.bot.reconnect(
|
|
|
|
event["server"].id, event["server"].connection_params))
|
2018-10-03 14:59:36 +00:00
|
|
|
|
|
|
|
@utils.hook("received.command.connect", min_args=1)
|
|
|
|
def connect(self, event):
|
|
|
|
"""
|
|
|
|
:help: Connect to a network
|
|
|
|
:usage: <server id>
|
2018-11-20 14:27:24 +00:00
|
|
|
:permission: connect
|
2018-10-03 14:59:36 +00:00
|
|
|
"""
|
|
|
|
id = event["args_split"][0]
|
|
|
|
if not id.isdigit():
|
2018-10-16 14:09:58 +00:00
|
|
|
raise utils.EventError("Please provide a numeric server ID")
|
2018-10-03 14:59:36 +00:00
|
|
|
|
|
|
|
id = int(id)
|
|
|
|
if not self.bot.database.servers.get(id):
|
2018-10-16 14:09:58 +00:00
|
|
|
raise utils.EventError("Unknown server ID")
|
2018-10-03 14:59:36 +00:00
|
|
|
|
|
|
|
existing_server = self.bot.get_server(id)
|
|
|
|
if existing_server:
|
2018-10-16 14:09:58 +00:00
|
|
|
raise utils.EventError("Already connected to %s" % str(
|
2018-10-03 14:59:36 +00:00
|
|
|
existing_server))
|
2018-10-16 14:09:58 +00:00
|
|
|
|
2018-10-03 14:59:36 +00:00
|
|
|
server = self.bot.add_server(id)
|
|
|
|
event["stdout"].write("Connecting to %s" % str(server))
|
2018-11-20 14:27:24 +00:00
|
|
|
|
|
|
|
@utils.hook("received.command.disconnect")
|
|
|
|
def disconnect(self, event):
|
|
|
|
"""
|
|
|
|
:help: Disconnect from a server
|
|
|
|
:usage: [server id]
|
|
|
|
:permission: disconnect
|
|
|
|
"""
|
|
|
|
id = event["server"].id
|
|
|
|
if event["args"]:
|
|
|
|
id = event["args_split"][0]
|
|
|
|
if not id.isdigit():
|
|
|
|
raise utils.EventError("Please provide a numeric server ID")
|
|
|
|
|
|
|
|
id = int(id)
|
|
|
|
if not self.bot.database.servers.get(id):
|
|
|
|
raise utils.EventError("Unknown server ID")
|
|
|
|
server = self.bot.get_server(id)
|
|
|
|
server.disconnect()
|
|
|
|
self.bot.disconnect(server)
|