本文整理汇总了Python中API.API.get_bot_nick方法的典型用法代码示例。如果您正苦于以下问题:Python API.get_bot_nick方法的具体用法?Python API.get_bot_nick怎么用?Python API.get_bot_nick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API.API
的用法示例。
在下文中一共展示了API.get_bot_nick方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from API import API [as 别名]
# 或者: from API.API import get_bot_nick [as 别名]
#.........这里部分代码省略.........
logging.info("Loading plugins")
self.plugins.load()
commands = {
"PING": self.ping,
"PRIVMSG": self.privmsg,
"JOIN": self.join,
"KICK": self.kick,
"PART": self.part,
"MODE": self.mode,
"QUIT": self.quit
}
logging.info("Starting main-loop")
self.API.send_command("PONG :127.0.0.1")
self.running = True
while self.running:
rlist, wlist, xlist = select([self.socket], [], [], sleep_time)
if rlist:
try:
msg = self.socket.recv(1024).decode()
except Exception as ex:
logging.exception(ex)
else:
for line in msg.splitlines():
logging.info(line)
args = line.split(" ")
if len(args) >= 1 and args[0] in commands:
commands[args[0]](args)
elif len(args) >= 2 and args[1] in commands:
commands[args[1]](args)
else:
pass
self.plugins.loop()
self.socket.close()
def ping(self, args: list) -> None:
# PING :127.0.0.1
if len(args) >= 2:
self.API.send_command("PONG " + args[1])
def privmsg(self, args: list) -> None:
if len(args) >= 4:
# :[email protected] PRIVMSG #Dev :plop
# ^^^^^^^^^^^ ^^^^
sender = args[0][1:args[0].find("!")] # Julien00859
channel = args[2] # #Dev
if channel in self.API.get_channels():
self.plugins.public_message(channel, sender, " ".join(args[3:len(args)])[1:])
elif channel == self.API.get_bot_nick():
self.plugins.private_message(sender, " ".join(args[3:len(args)])[1:])
def join(self, args: list) -> None:
if len(args) >= 3:
# :[email protected] JOIN :#Dev
# ^^^^^^^^^^^ ^^^^
sender = args[0][1:args[0].find("!")] # Julien00859
channel = args[2][1:] # #Dev
self.API.add_update_user(channel, sender)
self.plugins.join(channel, sender)
def kick(self, args: list) -> None:
# :[email protected] KICK #Dev Julien00859 :You have been kicked
# ^^^^^^^^^ ^^^^ ^^^^^^^^^^^
if len(args) >= 4:
sender = args[0][1:args[0].find("!")] # Julien008
self.API.remove_user(args[2], args[3])
self.plugins.kick(sender, args[2], args[3])
def part(self, args: list) -> None:
if len(args) >= 3:
# :[email protected] PART #Dev :"Gonna bake some cookies..."
# ^^^^^^^^^^^ ^^^^
sender = args[0][1:args[0].find("!")] # Julien00859
self.API.remove_user(args[2], sender)
self.plugins.part(args[2], sender)
def mode(self, args: list) -> None:
# :[email protected] MODE #Dev +h Julien00859
# ^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^
sender = args[0][1:args[0].find("!")] # Julien008
if len(args) >= 5:
self.API.send_names_query(args[2])
self.plugins.mode(sender, args[2], args[3], args[4])
def quit(self, args: list) -> None:
if len(args) >= 1:
# :[email protected] QUIT :Quit: Keep calm and do not rage quit
# ^^^^^^^^^^^
sender = args[0][1:args[0].find("!")] # Julien00859
for channel in self.API.get_channels():
self.API.remove_user(channel, sender)
self.plugins.quit(sender)