Skip to content

Commit 91d4cac

Browse files
committed
Add support for bot mode
1 parent c2f8860 commit 91d4cac

File tree

6 files changed

+128
-30
lines changed

6 files changed

+128
-30
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* * Copyright (C) 2013-2023 Matt Baxter https://kitteh.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use, copy,
8+
* modify, merge, publish, distribute, sublicense, and/or sell copies
9+
* of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.kitteh.irc.client.library.defaults.element.isupport;
25+
26+
import org.checkerframework.checker.nullness.qual.NonNull;
27+
import org.checkerframework.checker.nullness.qual.Nullable;
28+
import org.kitteh.irc.client.library.Client;
29+
import org.kitteh.irc.client.library.element.ISupportParameter;
30+
31+
/**
32+
* Default implementation of {@link Bot}.
33+
*/
34+
public class DefaultISupportBot extends DefaultISupportParameterValueRequired implements ISupportParameter.Bot {
35+
private final char mode;
36+
37+
/**
38+
* Constructs the object.
39+
*
40+
* @param client client
41+
* @param name parameter name
42+
* @param value parameter value, if present
43+
*/
44+
public DefaultISupportBot(@NonNull Client client, @NonNull String name, @Nullable String value) {
45+
super(client, name, value);
46+
this.mode = value.charAt(0);
47+
}
48+
49+
@Override
50+
public char getMode() {
51+
return this.mode;
52+
}
53+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* * Copyright (C) 2013-2023 Matt Baxter https://kitteh.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use, copy,
8+
* modify, merge, publish, distribute, sublicense, and/or sell copies
9+
* of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.kitteh.irc.client.library.defaults.element.messagetag;
25+
26+
import org.checkerframework.checker.nullness.qual.NonNull;
27+
import org.checkerframework.checker.nullness.qual.Nullable;
28+
import org.kitteh.irc.client.library.Client;
29+
import org.kitteh.irc.client.library.element.MessageTag;
30+
import org.kitteh.irc.client.library.feature.MessageTagManager;
31+
import org.kitteh.irc.client.library.util.TriFunction;
32+
33+
/**
34+
* Default implementation of {@link Bot}.
35+
*/
36+
public class DefaultMessageTagBot extends MessageTagManager.DefaultMessageTag implements MessageTag.Bot {
37+
/**
38+
* Function to create this message tag.
39+
*/
40+
@SuppressWarnings("ConstantConditions")
41+
public static final TriFunction<Client, String, String, DefaultMessageTagBot> FUNCTION = (client, name, value) -> new DefaultMessageTagBot(name, value);
42+
43+
private DefaultMessageTagBot(@NonNull String name, @Nullable String value) {
44+
super(name, value);
45+
}
46+
}

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,7 @@
2727
import org.checkerframework.checker.nullness.qual.Nullable;
2828
import org.kitteh.irc.client.library.Client;
2929
import org.kitteh.irc.client.library.defaults.element.DefaultISupportParameter;
30-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportAwayLen;
31-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportCaseMapping;
32-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportChanLimit;
33-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportChanModes;
34-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportChanTypes;
35-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportChannelLen;
36-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportClientTagDeny;
37-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportEList;
38-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportExcepts;
39-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportExtBan;
40-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportHostLen;
41-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportInvEx;
42-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportKickLen;
43-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportMaxList;
44-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportMaxTargets;
45-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportModes;
46-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportNetwork;
47-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportNickLen;
48-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportPrefix;
49-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportSilence;
50-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportStatusMsg;
51-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportTargMax;
52-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportTopicLen;
53-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportUserLen;
54-
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportWhoX;
30+
import org.kitteh.irc.client.library.defaults.element.isupport.*;
5531
import org.kitteh.irc.client.library.element.ISupportParameter;
5632
import org.kitteh.irc.client.library.exception.KittehServerISupportException;
5733
import org.kitteh.irc.client.library.feature.ISupportManager;
@@ -69,9 +45,10 @@ public class DefaultISupportManager extends AbstractNameValueProcessor<ISupportP
6945
*
7046
* @param client client for which this exists
7147
*/
72-
public DefaultISupportManager(Client.WithManagement client) {
48+
public DefaultISupportManager(Client.@NonNull WithManagement client) {
7349
super(client);
7450
this.registerParameter(ISupportParameter.AwayLen.NAME, DefaultISupportAwayLen::new);
51+
this.registerParameter(ISupportParameter.Bot.NAME, DefaultISupportBot::new);
7552
this.registerParameter(ISupportParameter.CaseMapping.NAME, DefaultISupportCaseMapping::new);
7653
this.registerParameter(ISupportParameter.ChannelLen.NAME, DefaultISupportChannelLen::new);
7754
this.registerParameter(ISupportParameter.ChanLimit.NAME, DefaultISupportChanLimit::new);

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
import org.checkerframework.checker.nullness.qual.NonNull;
2727
import org.checkerframework.checker.nullness.qual.Nullable;
2828
import org.kitteh.irc.client.library.Client;
29-
import org.kitteh.irc.client.library.defaults.element.messagetag.DefaultMessageTagLabel;
30-
import org.kitteh.irc.client.library.defaults.element.messagetag.DefaultMessageTagMsgId;
31-
import org.kitteh.irc.client.library.defaults.element.messagetag.DefaultMessageTagTime;
32-
import org.kitteh.irc.client.library.defaults.element.messagetag.DefaultMessageTagTyping;
29+
import org.kitteh.irc.client.library.defaults.element.messagetag.*;
3330
import org.kitteh.irc.client.library.element.MessageTag;
3431
import org.kitteh.irc.client.library.exception.KittehServerMessageTagException;
3532
import org.kitteh.irc.client.library.feature.CapabilityManager;
@@ -84,6 +81,7 @@ private TagCreator(@NonNull String capability, @NonNull TriFunction<Client, Stri
8481
*/
8582
public DefaultMessageTagManager(Client.WithManagement client) {
8683
super(client);
84+
this.registerTagCreator(CapabilityManager.Defaults.MESSAGE_TAGS, "bot", DefaultMessageTagBot.FUNCTION);
8785
this.registerTagCreator(CapabilityManager.Defaults.SERVER_TIME, "time", DefaultMessageTagTime.FUNCTION);
8886
this.registerTagCreator(CapabilityManager.Defaults.MESSAGE_TAGS, "msgid", DefaultMessageTagMsgId.FUNCTION);
8987
this.registerTagCreator(CapabilityManager.Defaults.LABELED_RESPONSE, "label", DefaultMessageTagLabel.FUNCTION);

src/main/java/org/kitteh/irc/client/library/element/ISupportParameter.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ interface AwayLen extends IntegerParameter {
7272
String NAME = "AWAYLEN";
7373
}
7474

75+
/**
76+
* Represents the server's support of bot mode, and indicates the usermode to self-flag as a bot.
77+
*/
78+
interface Bot extends ISupportParameter {
79+
/**
80+
* Parameter name.
81+
*/
82+
String NAME = "BOT";
83+
84+
/**
85+
* Gets the bot mode character.
86+
*
87+
* @return bot mode
88+
*/
89+
char getMode();
90+
}
91+
7592
/**
7693
* Represents the {@link org.kitteh.irc.client.library.feature.CaseMapping}
7794
* supported by the server.

src/main/java/org/kitteh/irc/client/library/element/MessageTag.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
* Reflects a message tag.
3333
*/
3434
public interface MessageTag {
35+
/**
36+
* Represents the `bot` tag, flagging any sender with {@link org.kitteh.irc.client.library.element.ISupportParameter.Bot} mode.
37+
*/
38+
interface Bot extends MessageTag {
39+
40+
}
41+
3542
/**
3643
* Represents the `label` tag as specified by the labeled responses spec.
3744
*/

0 commit comments

Comments
 (0)