use of sx.blah.discord.api.IDiscordClient in project DiscordSailv2 by Vaerys-Dawn.
the class Client method main.
public static void main(String[] args) {
IDiscordClient client = new ClientBuilder().withToken(args[0]).build();
client.getDispatcher().registerListener((IListener<ReadyEvent>) readyEvent -> System.out.println("login successful"));
client.login();
}
use of sx.blah.discord.api.IDiscordClient 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.IDiscordClient in project BoltBot by DiscordBolt.
the class BoltBot method registerModules.
private static void registerModules(IDiscordClient client) {
// API Modules
Logger.trace("Loading API modules.");
client.getDispatcher().registerListener(new DataSync(client));
commandManager = new CommandManager(client, "com.discordbolt.boltbot");
client.getGuilds().stream().map(g -> GuildData.getById(g.getLongID())).filter(Optional::isPresent).filter(gd -> gd.get().getCommandPrefix() != null).forEach(gd -> commandManager.setCommandPrefix(client.getGuildByID(gd.get().getGuildId()), gd.get().getCommandPrefix().charAt(0)));
Logger.trace("Finished loading API modules");
// Feature Modules
Logger.trace("Loading feature modules.");
client.getModuleLoader().loadModule(new MusicModule(client));
client.getModuleLoader().loadModule(new CuntModule(client));
client.getModuleLoader().loadModule(new DiceModule(client));
client.getModuleLoader().loadModule(new DisconnectModule(client));
client.getModuleLoader().loadModule(new RedditModule(client));
client.getModuleLoader().loadModule(new TableFixerModule(client));
client.getModuleLoader().loadModule(new SeenModule(client));
client.getModuleLoader().loadModule(new StatusModule(client));
client.getModuleLoader().loadModule(new TagModule(client));
client.getModuleLoader().loadModule(new TwitchModule(client));
Logger.trace("Finished loading feature modules.");
}
use of sx.blah.discord.api.IDiscordClient in project DiscordSailv2 by Vaerys-Dawn.
the class ProfileObject method addSailModNote.
public void addSailModNote(String contents, long timeStamp, boolean isStrike) {
if (modNotes == null)
modNotes = new LinkedList<>();
IDiscordClient client = Client.getClient();
modNotes.add(new ModNoteObject(contents, client.getOurUser().getLongID(), timeStamp, isStrike));
}
use of sx.blah.discord.api.IDiscordClient in project Discord4J by Discord4J.
the class BaseBot method login.
/**
* A custom login() method to handle all of the possible exceptions and set the bot instance.
*/
public static BaseBot login(String token) {
// Initializing the bot variable
BaseBot bot = null;
// Creates a new client builder instance
ClientBuilder builder = new ClientBuilder();
// Sets the bot token for the client
builder.withToken(token);
try {
// Builds the IDiscordClient instance and logs it in
IDiscordClient client = builder.login();
// Creating the bot instance
bot = new BaseBot(client);
} catch (DiscordException e) {
// Error occurred logging in
System.err.println("Error occurred while logging in!");
e.printStackTrace();
}
return bot;
}
Aggregations