本文整理汇总了Python中API.API.send_names_query方法的典型用法代码示例。如果您正苦于以下问题:Python API.send_names_query方法的具体用法?Python API.send_names_query怎么用?Python API.send_names_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API.API
的用法示例。
在下文中一共展示了API.send_names_query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from API import API [as 别名]
# 或者: from API.API import send_names_query [as 别名]
class Server:
def __init__(self):
# Chargement de la configuration
with open("config.json", "r") as json_data:
config = json.load(json_data)
host = config["host"]
port = config["port"]
sleep_time = config["sleepTime"]
nick = config["nickname"]
oper_password = config["oper_password"]
log_file = config["log_file"]
log_level = config["log_level"]
logging.basicConfig(filename=log_file,
filemode="a",
level=getattr(logging, log_level.upper()),
format='%(asctime)s [%(levelname)s | %(filename)s > %(funcName)s] %(message)s',
datefmt='%x %X')
stderr = open(log_file, "a")
logging.info("=== Starting bot ===")
logging.info("Loading API")
self.API = API(self)
logging.info("Loading plugins")
self.plugins = Plugins(self.API)
logging.info("Connecting to the IRC network")
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((host, port))
self.API.send_command("NICK {}".format(nick))
self.API.send_command("USER {} 0 * :Bot".format(nick))
while True:
motd = self.socket.recv(1024).decode()
if len(motd) > 0:
for line in motd.splitlines():
logging.info(line)
if "Current Global Users" in motd:
break
self.API.send_command("OPER Bot {}".format(oper_password))
for line in self.socket.recv(1024).decode().splitlines():
logging.info(line)
for channel in self.API.get_channels():
self.API.send_command("JOIN " + channel)
for line in self.socket.recv(1024).decode().splitlines():
logging.info(line)
self.API.send_command("SAMode {} +o {}".format(channel, nick))
for line in self.socket.recv(1024).decode().splitlines():
logging.info(line)
self.API.send_names_query(channel)
logging.info("Connected !")
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:
#.........这里部分代码省略.........