use of net.kodehawa.mantarobot.data.entities.helpers.GuildData in project MantaroBot by Mantaro.
the class TrackScheduler method announce.
private void announce() {
try {
DBGuild dbGuild = MantaroData.db().getGuild(guildId);
GuildData guildData = dbGuild.getData();
if (guildData.isMusicAnnounce()) {
AudioTrackContext atc = getCurrentTrack();
if (atc == null)
return;
TextChannel req = atc.getRequestedChannel();
if (req == null)
return;
VoiceChannel vc = req.getGuild().getSelfMember().getVoiceState().getChannel();
AudioTrackInfo trackInfo = getCurrentTrack().getInfo();
String title = trackInfo.title;
long trackLength = trackInfo.length;
if (req.canTalk()) {
getCurrentTrack().getRequestedChannel().sendMessage(String.format("📣 Now playing in **%s**: %s (%s)%s", vc.getName(), title, AudioUtils.getLength(trackLength), getCurrentTrack().getDJ() != null ? " requested by **" + getCurrentTrack().getDJ().getName() + "**" : "")).queue(message -> message.delete().queueAfter(90, TimeUnit.SECONDS));
}
}
} catch (Exception ignored) {
}
}
use of net.kodehawa.mantarobot.data.entities.helpers.GuildData in project MantaroBot by Mantaro.
the class MantaroListener method onUserJoin.
private void onUserJoin(GuildMemberJoinEvent event) {
try {
String role = MantaroData.db().getGuild(event.getGuild()).getData().getGuildAutoRole();
DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
GuildData data = dbg.getData();
String hour = df.format(new Date(System.currentTimeMillis()));
if (role != null) {
try {
event.getGuild().getController().addRolesToMember(event.getMember(), event.getGuild().getRoleById(role)).queue(s -> log.debug("Successfully added a new role to " + event.getMember()));
} catch (PermissionException e) {
MantaroData.db().getGuild(event.getGuild()).getData().setGuildAutoRole(null);
MantaroData.db().getGuild(event.getGuild()).save();
event.getGuild().getOwner().getUser().openPrivateChannel().queue(messageChannel -> messageChannel.sendMessage("Removed autorole since I don't have the permissions to assign that role").queue());
}
}
String logChannel = MantaroData.db().getGuild(event.getGuild()).getData().getGuildLogChannel();
if (logChannel != null) {
TextChannel tc = event.getGuild().getTextChannelById(logChannel);
tc.sendMessage(String.format("`[%s]` 📣 `%s#%s` just joined `%s` `(User #%d | ID:%s)`", hour, event.getMember().getEffectiveName(), event.getMember().getUser().getDiscriminator(), event.getGuild().getName(), event.getGuild().getMembers().size(), event.getGuild().getId())).queue();
logTotal++;
}
String joinChannel = MantaroData.db().getGuild(event.getGuild()).getData().getLogJoinLeaveChannel();
String joinMessage = MantaroData.db().getGuild(event.getGuild()).getData().getJoinMessage();
if (joinChannel != null && joinMessage != null) {
TextChannel tc = event.getGuild().getTextChannelById(joinChannel);
if (joinMessage.contains("$(")) {
Map<String, String> dynamicMap = new HashMap<>();
map("event", dynamicMap, event);
joinMessage = dynamicResolve(joinMessage, dynamicMap);
}
int c = joinMessage.indexOf(':');
if (c != -1) {
String m = joinMessage.substring(0, c);
String v = joinMessage.substring(c + 1);
if (m.equals("embed")) {
EmbedJSON embed;
try {
embed = GsonDataManager.gson(false).fromJson('{' + v + '}', EmbedJSON.class);
} catch (Exception ignored) {
tc.sendMessage(EmoteReference.ERROR2 + "The string ``{" + v + "}`` isn't a valid JSON.").queue();
return;
}
tc.sendMessage(embed.gen(event)).queue();
return;
}
}
tc.sendMessage(joinMessage).queue();
}
} catch (Exception e) {
}
}
Aggregations