mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-29 00:26:15 -04:00
Can PM .who or .players to the IRC bot to avoid unnecessary channel messages. (Thanks UclCommander)
This commit is contained in:
parent
0441e01580
commit
f6b073f7cc
@ -36,6 +36,7 @@ namespace MCGalaxy {
|
|||||||
private byte retries = 0;
|
private byte retries = 0;
|
||||||
public string usedCmd = "";
|
public string usedCmd = "";
|
||||||
Dictionary<string, List<string>> users = new Dictionary<string, List<string>>();
|
Dictionary<string, List<string>> users = new Dictionary<string, List<string>>();
|
||||||
|
static char[] trimChars = { ' ' };
|
||||||
|
|
||||||
public ForgeBot(string channel, string opchannel, string nick, string server) {
|
public ForgeBot(string channel, string opchannel, string nick, string server) {
|
||||||
this.channel = channel.Trim(); this.opchannel = opchannel.Trim(); this.nick = nick.Replace(" ", ""); this.server = server;
|
this.channel = channel.Trim(); this.opchannel = opchannel.Trim(); this.nick = nick.Replace(" ", ""); this.server = server;
|
||||||
@ -89,19 +90,24 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public void Say(string message, bool opchat = false, bool color = true) {
|
public void Say(string message, bool opchat = false, bool color = true) {
|
||||||
if (!Server.irc || !IsConnected()) return;
|
if (!Server.irc || !IsConnected()) return;
|
||||||
|
message = ConvertMessage(message, color);
|
||||||
if(String.IsNullOrEmpty(message.Trim()))
|
connection.Sender.PublicMessage(opchat ? opchannel : channel, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Pm(string user, string message, bool color = true) {
|
||||||
|
if (!Server.irc || !IsConnected()) return;
|
||||||
|
message = ConvertMessage(message, color);
|
||||||
|
connection.Sender.PrivateMessage(user, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
static string ConvertMessage(string message, bool color) {
|
||||||
|
if (String.IsNullOrEmpty(message.Trim()))
|
||||||
message = ".";
|
message = ".";
|
||||||
message = CP437Writer.ConvertToUnicode(message);
|
message = CP437Writer.ConvertToUnicode(message);
|
||||||
|
|
||||||
if (color)
|
if (color)
|
||||||
message = c.MinecraftToIrcColors(message.Replace("%r", ResetSignal));
|
message = c.MinecraftToIrcColors(message.Replace("%r", ResetSignal));
|
||||||
connection.Sender.PublicMessage(opchat ? opchannel : channel, message);
|
return message;
|
||||||
}
|
|
||||||
|
|
||||||
public void Pm(string user, string message) {
|
|
||||||
if (Server.irc && IsConnected())
|
|
||||||
connection.Sender.PrivateMessage(user, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset() {
|
public void Reset() {
|
||||||
@ -159,6 +165,19 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Listener_OnPrivate(UserInfo user, string message) {
|
void Listener_OnPrivate(UserInfo user, string message) {
|
||||||
|
message = c.IrcToMinecraftColors(message);
|
||||||
|
message = CP437Reader.ConvertToRaw(message);
|
||||||
|
string[] parts = message.Split(trimChars, 3);
|
||||||
|
string ircCmd = parts[0].ToLower();
|
||||||
|
if (ircCmd == ".who" || ircCmd == ".players") {
|
||||||
|
try {
|
||||||
|
CmdPlayers.DisplayPlayers(null, "", text => Pm(user.Nick, text));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Server.ErrorLog(e);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Server.ircControllers.Contains(user.Nick)) { Pm(user.Nick, "You are not an IRC controller!"); return; }
|
if (!Server.ircControllers.Contains(user.Nick)) { Pm(user.Nick, "You are not an IRC controller!"); return; }
|
||||||
if (message.Split(' ')[0] == "resetbot" || banCmd.Contains(message.Split(' ')[0])) { Pm(user.Nick, "You cannot use this command from IRC!"); return; }
|
if (message.Split(' ')[0] == "resetbot" || banCmd.Contains(message.Split(' ')[0])) { Pm(user.Nick, "You cannot use this command from IRC!"); return; }
|
||||||
if (Player.CommandHasBadColourCodes(null, message)) { Pm(user.Nick, "Your command had invalid color codes!"); return; }
|
if (Player.CommandHasBadColourCodes(null, message)) { Pm(user.Nick, "Your command had invalid color codes!"); return; }
|
||||||
@ -178,18 +197,17 @@ namespace MCGalaxy {
|
|||||||
void Listener_OnPublic(UserInfo user, string channel, string message) {
|
void Listener_OnPublic(UserInfo user, string channel, string message) {
|
||||||
message = c.IrcToMinecraftColors(message);
|
message = c.IrcToMinecraftColors(message);
|
||||||
message = CP437Reader.ConvertToRaw(message);
|
message = CP437Reader.ConvertToRaw(message);
|
||||||
string[] parts = message.Split(new char[] { ' ' }, 3);
|
string[] parts = message.Split(trimChars, 3);
|
||||||
//string allowedchars = "1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./!@#$%^*()_+QWERTYUIOPASDFGHJKL:\"ZXCVBNM<>? ";
|
string ircCmd = parts[0].ToLower();
|
||||||
// Allowed chars are any ASCII char between 20h/32 and 7Ah/122 inclusive, except for 26h/38 (&) and 60h/96 (`)
|
if (ircCmd == ".who" || ircCmd == ".players") {
|
||||||
string ircCommand = parts[0].ToLower();
|
|
||||||
if (ircCommand == ".who" || ircCommand == ".players") {
|
|
||||||
try {
|
try {
|
||||||
CmdPlayers.DisplayPlayers(null, "", text => Server.IRC.Say(text, false, true));
|
CmdPlayers.DisplayPlayers(null, "", text => Say(text, false, true));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Server.ErrorLog(e);
|
Server.ErrorLog(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ircCommand == ".x") {
|
|
||||||
|
if (ircCmd == ".x") {
|
||||||
if (Server.ircControllers.Contains(user.Nick))
|
if (Server.ircControllers.Contains(user.Nick))
|
||||||
{
|
{
|
||||||
List<string> chanNicks;
|
List<string> chanNicks;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user