parent
01db886917
commit
cf0d2e7d5d
1 changed files with 30 additions and 2 deletions
|
@ -44,10 +44,10 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
|| lastmsgtime / 1000000000f < nanoTime / 1000000000f - 120) {
|
|| lastmsgtime / 1000000000f < nanoTime / 1000000000f - 120) {
|
||||||
lastmessage = DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, "", embedObject);
|
lastmessage = DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, "", embedObject);
|
||||||
lastmsgtime = nanoTime;
|
lastmsgtime = nanoTime;
|
||||||
|
lastmsg = e.getMessage();
|
||||||
} else
|
} else
|
||||||
try {
|
try {
|
||||||
embedObject.description = lastmessage.getEmbeds().get(0).getDescription() + "\n"
|
lastmsg = embedObject.description = lastmsg + "\n" + embedObject.description;
|
||||||
+ embedObject.description;
|
|
||||||
DiscordPlugin.perform(() -> lastmessage.edit("", embedObject));
|
DiscordPlugin.perform(() -> lastmessage.edit("", embedObject));
|
||||||
} catch (MissingPermissionsException | DiscordException e1) {
|
} catch (MissingPermissionsException | DiscordException e1) {
|
||||||
TBMCCoreAPI.SendException("An error occured while editing chat message!", e1);
|
TBMCCoreAPI.SendException("An error occured while editing chat message!", e1);
|
||||||
|
@ -55,11 +55,39 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
} // TODO: Author URL
|
} // TODO: Author URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChatPreprocess(TBMCChatPreprocessEvent event) {
|
||||||
|
int start = -1;
|
||||||
|
// System.out.println("A");
|
||||||
|
while ((start = event.getMessage().indexOf('@', start + 1)) != -1) {
|
||||||
|
// System.out.println("Start: " + start);
|
||||||
|
int mid = event.getMessage().indexOf('#', start + 1);
|
||||||
|
// System.out.println("Mid: " + mid);
|
||||||
|
if (mid == -1)
|
||||||
|
return;
|
||||||
|
int end_ = event.getMessage().indexOf(' ', mid + 1);
|
||||||
|
// System.out.println("End: " + end_);
|
||||||
|
if (end_ == -1)
|
||||||
|
end_ = event.getMessage().length();
|
||||||
|
final int end = end_;
|
||||||
|
final int startF = start;
|
||||||
|
// System.out.println("Name: " + event.getMessage().substring(start, mid));
|
||||||
|
// System.out.println("Disc: " + event.getMessage().substring(mid, end));
|
||||||
|
DiscordPlugin.dc.getUsersByName(event.getMessage().substring(start + 1, mid)).stream()
|
||||||
|
.filter(u -> u.getDiscriminator().equals(event.getMessage().substring(mid + 1, end))).findAny()
|
||||||
|
.ifPresent(user -> event.setMessage(event.getMessage().substring(0, startF) + "@" + user.getName()
|
||||||
|
+ (event.getMessage().length() > end ? event.getMessage().substring(end)
|
||||||
|
: ""))); // TODO: Add formatting
|
||||||
|
start = end; // Skip any @s inside the mention
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final String[] UnconnectedCmds = new String[] { "list", "u", "shrug", "tableflip", "unflip", "mwiki",
|
private static final String[] UnconnectedCmds = new String[] { "list", "u", "shrug", "tableflip", "unflip", "mwiki",
|
||||||
"yeehaw" };
|
"yeehaw" };
|
||||||
|
|
||||||
private static IMessage lastmessage = null;
|
private static IMessage lastmessage = null;
|
||||||
private static long lastmsgtime = 0;
|
private static long lastmsgtime = 0;
|
||||||
|
private static String lastmsg;
|
||||||
private static short lastlist = 0;
|
private static short lastlist = 0;
|
||||||
private static short lastlistp = 0;
|
private static short lastlistp = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue