Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何使用 Wol 功能? #186

Open
glk-hll opened this issue Aug 17, 2022 · 2 comments
Open

如何使用 Wol 功能? #186

glk-hll opened this issue Aug 17, 2022 · 2 comments
Assignees
Labels
operation problem 用户操作问题

Comments

@glk-hll
Copy link

glk-hll commented Aug 17, 2022

如何使用用户贡献技能 Wol,我在 .wukong/config.yml 中设置以下配置:

    # WOL启动
    wol:
        enable: true
        ip: '192.168.1.255'
        mac: 'B0-25-AA-2F-9E-EA'

然后输入指令:开启电脑,只有机器人返回的一些回答,请问问题出来哪里?是需要去下载这些插件使用吗?

@glk-hll glk-hll added the operation problem 用户操作问题 label Aug 17, 2022
@prairiewolf12
Copy link

wukong-contrib-master里有这个插件

-- coding: utf-8--

import socket
from robot import config, logging
from robot.sdk.AbstractPlugin import AbstractPlugin

logger = logging.getLogger(name)

class Plugin(AbstractPlugin):

SLUG = "wol"

def Waker(self, ip, mac):
    global sent
    def to_hex_int(s):
        return int(s.upper(), 16)

    dest = (ip, 9)

    spliter = ""
    if mac.count(":") == 5: spliter = ":"
    if mac.count("-") == 5: spliter = "-"

    parts = mac.split(spliter)
    a1 = to_hex_int(parts[0])
    a2 = to_hex_int(parts[1])
    a3 = to_hex_int(parts[2])
    a4 = to_hex_int(parts[3])
    a5 = to_hex_int(parts[4])
    a6 = to_hex_int(parts[5])
    addr = [a1, a2, a3, a4, a5, a6]

    packet = chr(255) + chr(255) + chr(255) + chr(255) + chr(255) + chr(255)

    for n in range(0,16):
        for a in addr:
            packet = packet + chr(a)

    packet = packet + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0)

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
    s.sendto(packet,dest)

    if len(packet) == 108:
        sent = True

def handle(self, text, parsed):
    profile = config.get()
    if self.SLUG not in profile or \
        'ip' not in profile[self.SLUG] or \
        'mac' not in profile[self.SLUG]:
            self.say('WOL配置有误,插件使用失败', cache=True)
            return
    ip = profile[self.SLUG]['ip']
    mac = profile[self.SLUG]['mac']
    try:
        self.Waker(ip,mac)
        if sent:
            self.say('启动成功', cache=True)
    except Exception as e:
        logger.error(e)
        self.say('抱歉,启动失败', cache=True)


def isValid(self, text, parsed):
    return any(word in text for word in [u"开机", u"启动电脑", u"开电脑"])

@prairiewolf11
Copy link

插件里这句有问题s.sendto(packet,dest)
需要改成这样
s.sendto(packet.encode(),dest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
operation problem 用户操作问题
Projects
None yet
Development

No branches or pull requests

4 participants