use of com.chill.projects.bot.container.DiscordSet in project Frost by woojiahao.
the class AutomaticCommands method onGuildMemberJoin.
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
MessageEmbed embed = new EmbedCreator().createWelcomeEmbed(FrostEmbedType.WELCOME, new DiscordSet(event.getUser(), event.getGuild()));
event.getGuild().getTextChannelById(FrostGuildList.getFrostGuildByID(event.getGuild().getId()).getGeneralChannel()).sendMessage(embed).queue();
FrostRoles.assignRole(new DiscordSet(event.getUser(), event.getGuild()), RolesID.MEMBER);
if (event.getUser().isBot()) {
FrostRoles.assignRole(new DiscordSet(event.getUser(), event.getGuild()), RolesID.SLAVE);
}
}
use of com.chill.projects.bot.container.DiscordSet in project Frost by woojiahao.
the class AutomaticCommands method onGuildJoin.
@Override
public void onGuildJoin(GuildJoinEvent event) {
event.getGuild().getDefaultChannel().sendMessage(new JoinEmbeds(new DiscordSet(event.getGuild())).onBotJoinEmbed()).queue();
FrostGuildList.addFrostGuild(event.getGuild().getId(), event.getGuild().getDefaultChannel().getId(), event.getGuild().getDefaultChannel().getId());
}
use of com.chill.projects.bot.container.DiscordSet in project Frost by woojiahao.
the class FrostRoles method autoAssignRole.
public static void autoAssignRole(Guild guild) {
List<Member> members = guild.getMembers();
for (Member m : members) {
DiscordSet set = new DiscordSet(m.getUser(), guild);
assignRole(set, RolesID.MEMBER);
if (m.isOwner())
assignRole(set, RolesID.OWNER);
if (m.getUser().isBot())
assignRole(set, RolesID.SLAVE);
}
}
use of com.chill.projects.bot.container.DiscordSet in project Frost by woojiahao.
the class InvokedCommands method onMessageReceived.
@Override
public void onMessageReceived(MessageReceivedEvent event) {
Message message = event.getMessage();
if (message.getContentRaw().startsWith(Ref.PREFIX)) {
String[] command = (message.getContentRaw().substring(1) + " ").split(" ");
DiscordSet set = new DiscordSet(event.getAuthor(), event.getGuild(), event.getTextChannel());
commandAttempted(set, command);
}
}
use of com.chill.projects.bot.container.DiscordSet in project Frost by woojiahao.
the class SpamDetector method updateMap.
private void updateMap(DiscordSet set) {
String user = set.getUser().getId();
String guild = set.getGuild().getId();
int guildPos = 0;
if ((guildPos = hasGuildEntry(guild)) == -1) {
messageCount.add(new AbstractMap.SimpleEntry<>(guild, new HashMap<>()));
messageTimer.add(new AbstractMap.SimpleEntry<>(guild, new HashMap<>()));
guildPos = messageCount.size() - 1;
}
if (!hasUserEntry(user, guildPos)) {
messageCount.get(guildPos).getValue().put(user, 1L);
messageTimer.get(guildPos).getValue().put(user, System.currentTimeMillis());
int finalGuildPos = guildPos;
new Timer().schedule(new TimerTask() {
@Override
public void run() {
messageCount.get(finalGuildPos).getValue().remove(user);
messageTimer.get(finalGuildPos).getValue().remove(user);
}
}, RaidLimits.MESSAGE.getDuration());
return;
}
long currentMessageCount = messageCount.get(guildPos).getValue().get(user);
messageCount.get(guildPos).getValue().replace(user, currentMessageCount + 1);
if (messageCount.get(guildPos).getValue().get(user) > RaidLimits.MESSAGE.getMessageCount()) {
long firstMessageTime = messageTimer.get(guildPos).getValue().get(user);
long currentTime = System.currentTimeMillis();
if (currentTime - firstMessageTime <= RaidLimits.MESSAGE.getDuration()) {
FrostRoles.assignRole(set, RolesID.MUTED);
String loggingID = FrostGuildList.getFrostGuildByID(set.getGuild().getId()).getLoggingChannel();
set.getGuild().getTextChannelById(loggingID).sendMessage(set.getUser().getAsMention() + " was muted due " + "to spam").queue();
new FrostDirectMessage().sendPrivateMessage(set.getUser(), new EmbedBuilder().addField("Auto spam detection", "You have been muted for spam", false).build());
List<Message> toDelete = new MessageHistory(set.getFrom()).retrievePast(50).complete().stream().filter(m -> m.getAuthor().getId().equals(set.getUser().getId())).collect(Collectors.toList());
if (toDelete != null || toDelete.size() > 0) {
set.getGuild().getTextChannelById(set.getFrom().getId()).deleteMessages(toDelete).queue();
}
RaidersList.add(user, guild);
}
}
}
Aggregations