use of me.dreamvoid.miraimc.velocity.utils.AutoLoginObject in project MiraiMC by DreamVoid.
the class MiraiAutoLogin method addAutoLoginBot.
public boolean addAutoLoginBot(long Account, String Password, String Protocol) {
try {
// 获取现有的机器人列表
Yaml yaml = new Yaml();
InputStream inputStream = new FileInputStream(AutoLoginFile);
AutoLoginObject data = yaml.loadAs(inputStream, AutoLoginObject.class);
if (data.getAccounts() == null) {
data.setAccounts(new ArrayList<>());
}
// 新建用于添加进去的Map
AutoLoginObject.Accounts account = new AutoLoginObject.Accounts();
// account 节点
account.setAccount(Account);
// password 节点
AutoLoginObject.Password password = new AutoLoginObject.Password();
password.setKind("PLAIN");
password.setValue(Password);
account.setPassword(password);
// configuration 节点
AutoLoginObject.Configuration configuration = new AutoLoginObject.Configuration();
configuration.setDevice("device.json");
configuration.setProtocol(Protocol.toUpperCase());
account.setConfiguration(configuration);
// 添加
List<AutoLoginObject.Accounts> accounts = data.getAccounts();
accounts.add(account);
data.setAccounts(accounts);
Yaml yaml1 = new Yaml();
File writeName = AutoLoginFile;
try (FileWriter writer = new FileWriter(writeName);
BufferedWriter out = new BufferedWriter(writer)) {
out.write(yaml1.dumpAs(data, Tag.MAP, DumperOptions.FlowStyle.BLOCK));
out.flush();
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
use of me.dreamvoid.miraimc.velocity.utils.AutoLoginObject in project MiraiMC by DreamVoid.
the class MiraiAutoLogin method loadAutoLoginList.
public List<AutoLoginObject.Accounts> loadAutoLoginList() throws FileNotFoundException {
Yaml yaml = new Yaml(new Constructor(AutoLoginObject.class));
InputStream inputStream = new FileInputStream(AutoLoginFile);
AutoLoginObject data = yaml.loadAs(inputStream, AutoLoginObject.class);
if (data.getAccounts() == null) {
data.setAccounts(new ArrayList<>());
}
return data.getAccounts();
}
use of me.dreamvoid.miraimc.velocity.utils.AutoLoginObject in project MiraiMC by DreamVoid.
the class MiraiAutoLogin method delAutoLoginBot.
public boolean delAutoLoginBot(long Account) {
try {
// 获取现有的机器人列表
Yaml yaml = new Yaml();
InputStream inputStream = new FileInputStream(AutoLoginFile);
AutoLoginObject data = yaml.loadAs(inputStream, AutoLoginObject.class);
if (data.getAccounts() == null) {
data.setAccounts(new ArrayList<>());
}
for (AutoLoginObject.Accounts bots : data.getAccounts()) {
if (bots.getAccount() == Account) {
data.getAccounts().remove(bots);
break;
}
}
Yaml yaml1 = new Yaml();
File writeName = AutoLoginFile;
try (FileWriter writer = new FileWriter(writeName);
BufferedWriter out = new BufferedWriter(writer)) {
out.write(yaml1.dumpAs(data, Tag.MAP, DumperOptions.FlowStyle.BLOCK));
out.flush();
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
Aggregations