use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.
the class Logger method exception.
public void exception(@Nullable IUser author, @Nullable String message, Exception e, Class clazz, boolean post) {
String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
// stack trace as a string
String error = sw.toString();
pw.close();
try {
sw.close();
} catch (IOException e1) {
// Can ignore silently...
}
if (Main.getSelfUser() != null) {
IUser bot = Main.getSelfUser();
if (post) {
String shortError = error;
if (error.length() > 1250) {
shortError = error.substring(0, 1250);
}
EmbedBuilder em = new EmbedBuilder();
if (bot != null) {
em.withAuthorIcon(bot.getAvatarURL());
}
if (author != null) {
em.withAuthorName(author.getName());
em.withThumbnail(author.getAvatarURL());
}
em.withColor(239, 15, 0);
em.withFooterText(clazz.getName());
// Send to discord!
em.appendField("Time", timeStamp, true);
if (e.getMessage() != null) {
if (e.getMessage().length() > 1024) {
em.appendField("Exception", e.getMessage().substring(0, 1024), true);
} else {
em.appendField("Exception", e.getMessage(), true);
}
}
if (message != null) {
em.appendField("Message", message, true);
}
// Get DisCal guild and channel..
IGuild guild = Main.client.getGuildByID(266063520112574464L);
IChannel channel = guild.getChannelByID(302249332244217856L);
Message.sendMessage(em.build(), "```" + shortError + "```", channel);
}
}
// ALWAYS LOG TO FILE!
try {
FileWriter exceptions = new FileWriter(exceptionsFile, true);
exceptions.write("ERROR --- " + timeStamp + " ---" + MessageUtils.lineBreak);
if (author != null) {
exceptions.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
}
if (message != null) {
exceptions.write("message: " + message + MessageUtils.lineBreak);
}
exceptions.write(error + MessageUtils.lineBreak);
exceptions.close();
} catch (IOException io) {
io.printStackTrace();
}
}
use of sx.blah.discord.handle.obj.IGuild in project DiscordSailv2 by Vaerys-Dawn.
the class GuildCreateListener method onGuildCreateEvent.
@EventSubscriber
public void onGuildCreateEvent(GuildCreateEvent event) {
IGuild guild = event.getGuild();
long guildID = guild.getLongID();
logger.debug("Starting Loading process for Guild with ID: " + guildID);
if (new File(Utility.getDirectory(guildID)).exists()) {
PatchHandler.guildPatches(guild);
}
FileHandler.createDirectory(Utility.getDirectory(guildID));
FileHandler.createDirectory(Utility.getDirectory(guildID, true));
FileHandler.createDirectory(Utility.getGuildImageDir(guildID));
FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_INFO));
GuildObject guildObject = new GuildObject(guild);
Globals.initGuild(guildObject);
logger.info("Finished Loading Guild With ID: " + guildID);
}
use of sx.blah.discord.handle.obj.IGuild in project DiscordSailv2 by Vaerys-Dawn.
the class GuildConfig method validateRoles.
public void validateRoles() {
IGuild guild = Globals.client.getGuildByID(guildID);
if (guild == null) {
return;
}
ListIterator iterator = cosmeticRoleIDs.listIterator();
while (iterator.hasNext()) {
IRole role = guild.getRoleByID((Long) iterator.next());
if (role == null) {
iterator.remove();
}
}
iterator = modifierRoleIDs.listIterator();
while (iterator.hasNext()) {
IRole role = guild.getRoleByID((Long) iterator.next());
if (role == null) {
iterator.remove();
}
}
IRole inviteAllowedRole = guild.getRoleByID(inviteAllowedID);
if (inviteAllowedRole == null) {
inviteAllowedID = -1;
}
IRole mutedRole = guild.getRoleByID(mutedRoleID);
if (mutedRole == null) {
mutedRoleID = -1;
}
IRole roleToMention = guild.getRoleByID(roleToMentionID);
if (roleToMention == null) {
roleToMentionID = -1;
}
iterator = rewardRoles.listIterator();
while (iterator.hasNext()) {
RewardRoleObject reward = (RewardRoleObject) iterator.next();
IRole role = guild.getRoleByID(reward.getRoleID());
if (role == null) {
iterator.remove();
}
}
}
use of sx.blah.discord.handle.obj.IGuild in project DiscordSailv2 by Vaerys-Dawn.
the class GetGuildList method execute.
@Override
public String execute(String args, CommandObject command) {
ArrayList<String> guilds = new ArrayList<>();
for (IGuild g : command.client.get().getGuilds()) {
guilds.add(g.getName() + ": " + g.getLongID());
}
XEmbedBuilder builder = new XEmbedBuilder(command);
Utility.listFormatterEmbed("List Of Guilds", builder, guilds, false);
command.user.sendEmbededDm("", builder);
return null;
}
use of sx.blah.discord.handle.obj.IGuild in project Shadbot by Shadorc.
the class ShutdownCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
MessageManager.addListener(context.getChannel(), this);
BotUtils.sendMessage(String.format(Emoji.QUESTION + " Do you really want to shutdown %s ? Yes/No", context.getClient().getOurUser().mention()), context.getChannel());
return;
}
List<String> splitArgs = StringUtils.split(context.getArg(), 2);
if (splitArgs.size() != 2) {
throw new MissingArgumentException();
}
Integer delay = CastUtils.asPositiveInt(splitArgs.get(0));
if (delay == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid time.", splitArgs.get(0)));
}
String message = splitArgs.get(1);
for (IGuild guild : context.getClient().getGuilds()) {
GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(guild.getLongID());
if (guildMusic != null && guildMusic.getChannel() != null) {
BotUtils.sendMessage(Emoji.INFO + " " + message, guildMusic.getChannel());
}
}
Shadbot.getScheduler().schedule(() -> System.exit(0), delay, TimeUnit.SECONDS);
LogUtils.warnf("Shadbot will restart in %d seconds. (Message: %s)", delay, message);
}
Aggregations