use of sx.blah.discord.api.events.EventDispatcher in project S-argo by Expugn.
the class Sargo method main.
public static void main(String[] args) {
File settingsFile = new File("data/Settings.xml");
if (!(settingsFile.exists())) {
LOGGER.error("\nSettings.xml is not found!\nPlace it in the appropriate location before continuing.");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.exit(0);
}
System.exit(0);
}
Reload.silentReloadSettings();
CLIENT = buildBot(SettingsParser.getBotToken());
EventDispatcher dispatcher = CLIENT.getDispatcher();
dispatcher.registerListener(new ReadyListener(CLIENT));
dispatcher.registerListener(new MessageListener(CLIENT));
}
use of sx.blah.discord.api.events.EventDispatcher in project DisCal-Discord-Bot by NovaFox161.
the class Main method main.
public static void main(String[] args) throws IOException {
// Get bot settings
Properties p = new Properties();
p.load(new FileReader(new File("settings.properties")));
BotSettings.init(p);
// Init logger
Logger.getLogger().init();
// Log in to discord
client = createClient(BotSettings.TOKEN.get());
if (client == null)
throw new NullPointerException("Failed to log in! Client cannot be null!");
UpdateDisPwData.init();
Authorization.getAuth().init();
// Connect to MySQL
DatabaseManager.getManager().connectToMySQL();
DatabaseManager.getManager().createTables();
// Start spark (catch any issues from it so only the site goes down without affecting bot....
try {
DiscordAccountHandler.getHandler().init();
SparkUtils.initSpark();
} catch (Exception e) {
Logger.getLogger().exception(null, "'Spark ERROR' by 'PANIC! AT THE WEBSITE'", e, Main.class, true);
}
// Register events
EventDispatcher dispatcher = client.getDispatcher();
dispatcher.registerListener(new ReadyEventListener());
// Register modules
CommandExecutor executor = CommandExecutor.getExecutor().enable();
executor.registerCommand(new HelpCommand());
executor.registerCommand(new DisCalCommand());
executor.registerCommand(new CalendarCommand());
executor.registerCommand(new AddCalendarCommand());
executor.registerCommand(new LinkCalendarCommand());
executor.registerCommand(new TimeCommand());
executor.registerCommand(new EventListCommand());
executor.registerCommand(new EventCommand());
executor.registerCommand(new RsvpCommand());
executor.registerCommand(new AnnouncementCommand());
executor.registerCommand(new DevCommand());
// Load language files.
MessageManager.loadLangs();
// Accept commands
ConsoleCommandExecutor.init();
}
use of sx.blah.discord.api.events.EventDispatcher in project DiscordSailv2 by Vaerys-Dawn.
the class Main method main.
public static void main(String[] args) throws UnknownHostException {
// important, do not move
PatchHandler.preInitPatches();
logger = LoggerFactory.getLogger(Main.class);
logger.info("Starting bot...");
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info(">>> Running Shutdown Process <<<");
if (Globals.savingFiles) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Utility.sendStack(e);
}
}
Globals.saveFiles(true);
}
});
String token = null;
// you need to set a token in Token/Token.txt for the bot to run
try {
Discord4J.disableAudio();
FileHandler.createDirectory(Constants.DIRECTORY_STORAGE);
FileHandler.createDirectory(Constants.DIRECTORY_GLOBAL_IMAGES);
FileHandler.createDirectory(Constants.DIRECTORY_COMP);
FileHandler.createDirectory(Constants.DIRECTORY_BACKUPS);
FileHandler.createDirectory(Constants.DIRECTORY_TEMP);
FileHandler.createDirectory(Constants.DIRECTORY_OLD_FILES);
FileHandler.createDirectory(Constants.DIRECTORY_ERROR);
// load config phase 1
Config config = (Config) Config.create(Constants.FILE_CONFIG, new Config());
GlobalData globalData = (GlobalData) GlobalData.create(Constants.FILE_GLOBAL_DATA, new GlobalData());
config = Config.check(config);
// getting bot token
try {
token = FileHandler.readFromFile(Constants.FILE_TOKEN).get(0);
} catch (IndexOutOfBoundsException e) {
logger.error("!!!BOT TOKEN NOT VALID PLEASE CHECK \"Storage/Token.txt\" AND UPDATE THE TOKEN!!!");
System.exit(Constants.EXITCODE_STOP);
}
try {
List<String> pastebinToken = FileHandler.readFromFile(Constants.FILE_PASTEBIN_TOKEN);
Client.initPastebin(pastebinToken);
} catch (IndexOutOfBoundsException e) {
logger.info("No Pastebin Token found.");
}
// stuff that i cant getToggles to work because reasons, ignore completely
// try{
// List<String> richPresesnce = FileHandler.readFromFile(Constants.FILE_RPC_TOKEN);
// Client.initRichPresence(richPresesnce);
// }catch (IndexOutOfBoundsException e){
// logger.info("Rich presence information missing.");
// }
// try {
// List<String> imgurToken = FileHandler.readFromFile(Constants.FILE_IMGUR_TOKEN);
// Client.initImgur(imgurToken);
// } catch (IndexOutOfBoundsException e) {
// logger.info("No Patreon Token found.");
// }
IDiscordClient client = Client.createClient(token, false);
// load config phase 2
Globals.initConfig(client, config, globalData);
if (Globals.creatorID == 153159020528533505L) {
try {
List<String> patreonToken = FileHandler.readFromFile(Constants.FILE_PATREON_TOKEN);
Client.initPatreon(patreonToken);
} catch (IndexOutOfBoundsException e) {
logger.info("No Patreon Token found.");
}
}
Globals.validateConfig();
if (Globals.errorStack != null) {
logger.error(">\n> Begin Config Error Report <<\n" + "at " + Constants.DIRECTORY_STORAGE + Constants.FILE_CONFIG + "\n" + Globals.errorStack + ">> End Error Report <<");
System.exit(Constants.EXITCODE_STOP);
}
ThreadGroup group = new ThreadGroup("GuildCreateGroup");
final int[] count = new int[] { 0 };
// login + register listener.
client.login();
// initialize creatorID if it is completely unset:
if (config.creatorID == 0) {
IUser botOwner = client.getApplicationOwner();
config.creatorID = botOwner.getLongID();
Globals.creatorID = config.creatorID;
logger.info("Default creatorID set to user " + botOwner.getName() + "#" + botOwner.getDiscriminator());
// save it back out to file.
config.flushFile();
}
ExecutorService guildService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
ExecutorService commandService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
ExecutorService creatorService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
EventDispatcher dispatcher = client.getDispatcher();
dispatcher.registerListener(guildService, new GuildCreateListener());
dispatcher.registerListener(commandService, new AnnotationListener());
dispatcher.registerListener(creatorService, new CreatorHandler());
dispatcher.registerTemporaryListener(new InitEvent());
// validate config file
Globals.setVersion();
// Init Patch system.
// timed events getSlashCommands
new TimerHandler();
} catch (DiscordException ex) {
logger.error(ex.getErrorMessage());
} catch (RateLimitException e) {
Utility.sendStack(e);
}
}
use of sx.blah.discord.api.events.EventDispatcher in project solinia3-core by mixxit.
the class Solinia3CorePlugin method setupDiscordClient.
private void setupDiscordClient() {
this.discordClient = createClient(this.discordbottoken, true);
EventDispatcher dispatcher = this.discordClient.getDispatcher();
dispatcher.registerListener(new DiscordListener(this));
}
use of sx.blah.discord.api.events.EventDispatcher in project DisCal-Discord-Bot by NovaFox161.
the class CommandExecutor method enable.
/**
* Enables the CommandExecutor and sets up the Listener.
* @return The CommandExecutor's instance.
*/
public CommandExecutor enable() {
EventDispatcher dispatcher = Main.client.getDispatcher();
dispatcher.registerListener(new CommandListener(this));
return instance;
}
Aggregations