Skip to content

Commit

Permalink
PkgAnn: add package Announcement
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed Apr 11, 2022
1 parent 98e29e7 commit dcdcc58
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/itxtech/mcl/component/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public static class PackageIndex {
}

public static class PackageInfo {
public String name;
public String announcement;
public String type;
public String defaultChannel;
Expand All @@ -244,6 +245,10 @@ public String getLatestVersion(String chan) {
var c = channels.get(chan);
return c.get(c.size() - 1);
}

public String getName(String id) {
return name == null ? id : name;
}
}

public static class RepoInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public String getName() {

@Override
public void load() {
loader.logger.info("Fetching MCL Announcement...");
loader.logger.debug("Fetching MCL Announcement...");
try {
var pkg = loader.repo.fetchPackage("org.itxtech:mcl");
loader.logger.info("Mirai Console Loader Announcement:");
loader.logger.println(pkg.announcement);
} catch (Exception e) {
loader.logger.error("Failed to fetch announcement.");
loader.logger.error("Failed to fetch MCL announcement.");
}
}
}
49 changes: 49 additions & 0 deletions src/main/java/org/itxtech/mcl/module/builtin/PkgAnn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.itxtech.mcl.module.builtin;

import org.fusesource.jansi.Ansi;
import org.itxtech.mcl.module.MclModule;

/*
*
* Mirai Console Loader
*
* Copyright (C) 2020-2022 iTX Technologies
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author PeratX
* @website https://github.com/iTXTech/mirai-console-loader
*
*/
public class PkgAnn extends MclModule {
@Override
public String getName() {
return "pkgann";
}

@Override
public void boot() {
for (var pkg : loader.packageManager.getPackages()) {
try {
var info = loader.repo.fetchPackage(pkg.id);
if (info.announcement != null) {
loader.logger.info(Ansi.ansi().fgBrightYellow().a(info.getName(pkg.id)).reset().a(" Announcement:"));
loader.logger.println(info.announcement);
}
} catch (Exception e) {
loader.logger.error("Failed to fetch announcement for \"" + pkg.id + "\"");
}
}
}
}
47 changes: 25 additions & 22 deletions src/main/java/org/itxtech/mcl/module/builtin/RepoCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,30 @@

import java.util.HashMap;

/*
*
* Mirai Console Loader
*
* Copyright (C) 2020-2022 iTX Technologies
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author PeratX
* @website https://github.com/iTXTech/mirai-console-loader
*
*/
public class RepoCache extends MclModule {
private static final String DISABLED_KEY = "repowithcache.disabled";
private static final String AUTO_CLEAR_KEY = "repowithcache.auto-clear";

@Override
Expand All @@ -18,38 +40,19 @@ public String getName() {

@Override
public void prepare() {
var mainGroup = new OptionGroup();
mainGroup.addOption(Option.builder().desc("Disable Repo With Cache")
.longOpt("disable-repo-with-cache").build());
mainGroup.addOption(Option.builder().desc("Enable Repo With Cache")
.longOpt("enable-repo-with-cache").build());
loader.options.addOptionGroup(mainGroup);


var clearGroup = new OptionGroup();
clearGroup.addOption(Option.builder().desc("Disable Repo With Cache auto clear")
.longOpt("disable-auto-clear").build());
clearGroup.addOption(Option.builder().desc("Enable Repo With Cache auto clear")
.longOpt("enable-auto-clear").build());
loader.options.addOptionGroup(clearGroup);

if (loader.config.moduleProps.getOrDefault(DISABLED_KEY, "false").equals("false")) {
loader.repo = new RepoWithCache(loader.repo);
loader.logger.debug("RepoWithCache has been initialized");
}
loader.repo = new RepoWithCache(loader.repo);
loader.logger.debug("RepoWithCache has been initialized. Run \"./mcl --disable-module repowithcache\" to disable.");
}

@Override
public void cli() {
if (loader.cli.hasOption("disable-repo-with-cache")) {
loader.config.moduleProps.put(DISABLED_KEY, "true");
loader.logger.info("RepoWithCache has been disabled. Restart MCL to take effect.");
}
if (loader.cli.hasOption("enable-repo-with-cache")) {
loader.config.moduleProps.put(DISABLED_KEY, "false");
loader.logger.info("RepoWithCache has been enabled. Restart MCL to take effect.");
}

if (loader.cli.hasOption("enable-auto-clear")) {
loader.config.moduleProps.put(AUTO_CLEAR_KEY, "true");
}
Expand Down

0 comments on commit dcdcc58

Please sign in to comment.