forked from Fascinated/Bat
Merge branch 'master' of https://git.fascinated.cc/Fascinated/Bat
# Conflicts: # src/main/java/cc/fascinated/bat/command/Category.java
This commit is contained in:
src/main/java/cc/fascinated/bat
command
common
config
event
features
autorole
base
logging
messagesnipe
moderation
reminder
spotify/command
welcomer
model
service
@ -138,6 +138,7 @@ public class CommandService extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
|
||||
long before = System.currentTimeMillis();
|
||||
Guild discordGuild = event.getGuild();
|
||||
if (event.getUser().isBot()) {
|
||||
return;
|
||||
@ -230,9 +231,10 @@ public class CommandService extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Executing command \"{}\" for user \"{}\"", commandName, user.getDiscordUser().getName());
|
||||
executor.execute(guild, user, ranInsideGuild ? event.getChannel().asTextChannel() : event.getChannel().asPrivateChannel(),
|
||||
event.getMember(), event.getInteraction());
|
||||
log.info("Executed command \"{}\" for user \"{}\" (took: {}ms)", commandName, user.getDiscordUser().getName(),
|
||||
System.currentTimeMillis() - before);
|
||||
} catch (Exception ex) {
|
||||
log.error("An error occurred while executing command \"{}\"", commandName, ex);
|
||||
event.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
|
@ -16,6 +16,7 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
|
||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent;
|
||||
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEvent;
|
||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
|
||||
@ -290,4 +291,17 @@ public class EventService extends ListenerAdapter {
|
||||
listener.onUserUpdateAvatar(user, event.getOldAvatarUrl(), event.getNewAvatarUrl(), event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) {
|
||||
if (event.getEntity().getUser().isBot()) {
|
||||
return;
|
||||
}
|
||||
BatGuild guild = guildService.getGuild(event.getEntity().getGuild().getId());
|
||||
BatUser user = userService.getUser(event.getEntity().getUser().getId());
|
||||
|
||||
for (EventListener listener : LISTENERS) {
|
||||
listener.onGuildVoiceUpdate(guild, user, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class MongoService {
|
||||
public static MongoService INSTANCE;
|
||||
private final MongoTemplate mongo;
|
||||
private final MongoTemplate mongoTemplate;
|
||||
|
||||
@Autowired
|
||||
public MongoService(MongoTemplate mongo) {
|
||||
INSTANCE = this;
|
||||
this.mongo = mongo;
|
||||
this.mongoTemplate = mongo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -26,7 +26,7 @@ public class MongoService {
|
||||
* @return The guilds collection
|
||||
*/
|
||||
public MongoCollection<Document> getGuildsCollection() {
|
||||
return mongo.getCollection("guilds");
|
||||
return mongoTemplate.getCollection("guilds");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,6 +35,6 @@ public class MongoService {
|
||||
* @return The users collection
|
||||
*/
|
||||
public MongoCollection<Document> getUsersCollection() {
|
||||
return mongo.getCollection("users");
|
||||
return mongoTemplate.getCollection("users");
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.mongodb.client.model.Filters;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent;
|
||||
import org.bson.Document;
|
||||
@ -57,23 +58,28 @@ public class UserService implements EventListener {
|
||||
if (users.containsKey(id)) {
|
||||
return users.get(id);
|
||||
}
|
||||
if (DiscordService.JDA.getUserById(id) == null) {
|
||||
log.warn("Attempted to get user with ID \"{}\" but it does not exist", id);
|
||||
User user = DiscordService.JDA.getUserById(id);
|
||||
if (user == null) {
|
||||
log.warn("Attempted to get user with ID \"{}\" but they do not exist", id);
|
||||
return null;
|
||||
}
|
||||
if (user.isBot()) {
|
||||
log.warn("Attempted to get user with ID \"{}\" but they are a bot", id);
|
||||
return null;
|
||||
}
|
||||
// User is not cached
|
||||
Document document = MongoService.INSTANCE.getUsersCollection().find(Filters.eq("_id", id)).first();
|
||||
if (document != null) {
|
||||
BatUser user = new BatUser(id, document);
|
||||
users.put(id, user);
|
||||
log.info("Loaded user \"{}\" in {}ms", user.getName(),System.currentTimeMillis() - before);
|
||||
return user;
|
||||
BatUser batUser = new BatUser(id, document);
|
||||
users.put(id, batUser);
|
||||
log.info("Loaded user \"{}\" in {}ms", batUser.getName(),System.currentTimeMillis() - before);
|
||||
return batUser;
|
||||
}
|
||||
// New user
|
||||
BatUser user = new BatUser(id, new Document());
|
||||
users.put(id, user);
|
||||
BatUser batUser = new BatUser(id, new Document());
|
||||
users.put(id, batUser);
|
||||
log.info("Created user \"{}\" - \"{}\"", user.getName(), user.getId());
|
||||
return user;
|
||||
return batUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,7 +98,6 @@ public class UserService implements EventListener {
|
||||
|
||||
@Override
|
||||
public void onUserUpdateGlobalName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateGlobalNameEvent event) {
|
||||
log.info("User \"{}\" changed their name from \"{}\" to \"{}\"", user.getName(), oldName, newName);
|
||||
user.setGlobalName(newName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user