-
Notifications
You must be signed in to change notification settings - Fork 0
bot
MidCoard edited this page Apr 25, 2022
·
3 revisions
通过本框架,你能够轻松登陆,登出,重新登陆机器人,同时无需过多担心机器人的配置问题。同样,由于默认是安卓PAD登陆,所以你也无需担心会和自己手机登陆、电脑登陆存在冲突的问题。
在BotManager
中,你可以通过BotManager#login(long,String,Plugin)
和BotManager#loginDirectyly(long,String,Plugin)
来登陆机器人。第二个方法是一个阻塞方法,他会一直等待机器人登陆成功。如果由于某些不确定因素,机器人登陆失败了,则会抛出一个BotLoginException
的异常。
package top.focess.qq.plugin.example;
import top.focess.qq.FocessQQ;
import top.focess.qq.api.plugin.Plugin;
import top.focess.qq.api.plugin.PluginType;
import java.util.concurrent.Future;
@PluginType
public class TestPlugin extends Plugin {
@Override
public void enable() {
try {
FocessQQ.getBotManager().loginDirectly(123456789, "password", this);
} catch (BotLoginException e) {
e.printStackTrace();
}
Future<Bot> botFuture = FocessQQ.getBotManager().login(123456789, "password", this);
try {
botFuture.get();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void disable() {
}
}
你不需要在Plugin#disable()
方法里面登出机器人,机器人会在框架关闭的时候自动登出。
当你拿到一个机器人实例时,你可以通过Bot#login()
、Bot#logout()
和Bot#relogin()
三个方法来登陆、登出、重新登陆机器人。BotManager#login(Bot)
、BotManager#logout(Bot)
和BotManager#relogin(Bot)
亦是如此。同时,你可以通过BotManager#getBot(long)
来获取机器人实例,通过BotManager#getBots()
来获取所有机器人实例,还可以通过BotManager#remove(long)
来移除机器人实例。
package top.focess.qq.plugin.example;
import top.focess.qq.FocessQQ;
import top.focess.qq.api.bot.Bot;
import top.focess.qq.api.plugin.Plugin;
import top.focess.qq.api.plugin.PluginType;
@PluginType
public class TestPlugin extends Plugin {
@Override
public void enable() {
Bot bot = FocessQQ.getBot();
bot.login();
bot.logout();
bot.relogin();
}
@Override
public void disable() {
}
}
当框架启动时,你需要在启动参数指定一个默认机器人或者在启动后手动键入默认机器人参数。如果默认机器人登陆失败,则框架会直接关闭。