Skip to content

Commit 79ca07f

Browse files
committed
Custom user mode support
1 parent 80765ad commit 79ca07f

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/main/java/org/kitteh/irc/client/library/defaults/feature/DefaultServerInfo.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public class DefaultServerInfo implements ServerInfo.WithManagement {
6363
private List<String> motd;
6464
private String address;
6565
private String version;
66-
private List<UserMode> userModes;
66+
private final List<UserMode> userModes = new CopyOnWriteArrayList<>();
67+
private final List<UserMode> customUserModes = new CopyOnWriteArrayList<>();
6768

6869
// Pattern: ([#!&\+][^ ,\07\r\n]{1,49})
6970
// Screw it, let's assume IRCDs disregard length policy
@@ -93,19 +94,22 @@ public DefaultServerInfo(@NonNull Client client) {
9394
defaultChannelUserModes.add(new DefaultChannelUserMode(client, 'o', '@')); // OP
9495
defaultChannelUserModes.add(new DefaultChannelUserMode(client, 'v', '+')); // Voice
9596
this.defaultChannelUserModes = Collections.unmodifiableList(defaultChannelUserModes);
96-
List<UserMode> defaultUserModes = new ArrayList<>(4);
97-
defaultUserModes.add(new DefaultUserMode(client, 'i')); // Invisible
98-
defaultUserModes.add(new DefaultUserMode(client, 's')); // Can receive server notices
99-
defaultUserModes.add(new DefaultUserMode(client, 'w')); // Can receive wallops
100-
defaultUserModes.add(new DefaultUserMode(client, 'o')); // Operator
101-
this.userModes = Collections.unmodifiableList(defaultUserModes);
97+
this.userModes.add(new DefaultUserMode(client, 'i')); // Invisible
98+
this.userModes.add(new DefaultUserMode(client, 's')); // Can receive server notices
99+
this.userModes.add(new DefaultUserMode(client, 'w')); // Can receive wallops
100+
this.userModes.add(new DefaultUserMode(client, 'o')); // Operator
102101
}
103102

104103
@Override
105104
public void addCustomChannelMode(@NonNull ChannelMode mode) {
106105
this.customChannelModes.add(Sanity.nullCheck(mode, "mode"));
107106
}
108107

108+
@Override
109+
public void addCustomUserMode(@NonNull UserMode mode) {
110+
this.customUserModes.add(Sanity.nullCheck(mode, "mode"));
111+
}
112+
109113
@Override
110114
public @NonNull Optional<String> getAddress() {
111115
return Optional.ofNullable(this.address);
@@ -202,12 +206,17 @@ public boolean isValidChannel(@NonNull String name) {
202206

203207
@Override
204208
public @NonNull List<UserMode> getUserModes() {
205-
return this.userModes;
209+
List<UserMode> list = new ArrayList<>();
210+
Set<Character> customModeChar = this.customUserModes.stream().map(Mode::getChar).collect(Collectors.toSet());
211+
this.userModes.stream().filter(mode -> !customModeChar.contains(mode.getChar())).forEach(list::add);
212+
list.addAll(this.customUserModes);
213+
return list;
206214
}
207215

208216
@Override
209217
public void setUserModes(@NonNull List<UserMode> userModes) {
210-
this.userModes = Collections.unmodifiableList(userModes);
218+
this.userModes.clear();
219+
this.userModes.addAll(userModes);
211220
}
212221

213222
@Override

src/main/java/org/kitteh/irc/client/library/feature/ServerInfo.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,21 @@ interface WithManagement extends ServerInfo {
9090
}
9191

9292
/**
93-
* Adds a custom mode, for a server that doesn't correctly list modes.
93+
* Adds a custom channel mode, for a server that doesn't correctly list
94+
* modes.
9495
*
9596
* @param mode custom mode to support
9697
*/
9798
void addCustomChannelMode(@NonNull ChannelMode mode);
9899

100+
/**
101+
* Adds a custom user mode, for a server that doesn't correctly list
102+
* modes.
103+
*
104+
* @param mode custom mode to support
105+
*/
106+
void addCustomUserMode(@NonNull UserMode mode);
107+
99108
/**
100109
* Gets the server-stated address of the server.
101110
*

0 commit comments

Comments
 (0)