本文整理汇总了C#中IncomingMessage.SendChat方法的典型用法代码示例。如果您正苦于以下问题:C# IncomingMessage.SendChat方法的具体用法?C# IncomingMessage.SendChat怎么用?C# IncomingMessage.SendChat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IncomingMessage
的用法示例。
在下文中一共展示了IncomingMessage.SendChat方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleCommand
public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
{
CommandManager commands = CommandManager.GetInstance();
if (!msg.HasMessage())
{
msg.SendChat("Available commands: " + commands.AvailableCommands());
return;
}
string cmd = msg.Message.ToLower();
if (!commands.HasCommand(cmd))
{
msg.SendChat("No help for command: " + cmd);
}
else
{
string help = commands.GetCommand(cmd).Help();
if (help == null || help.Equals(""))
{
msg.SendChat("No help available for: " + cmd);
}
else
{
msg.SendChat("Help for " + cmd + ": " + help);
}
}
}
示例2: HandleCommand
public void HandleCommand(IRCServer server, string command, IncomingMessage message)
{
if (!message.HasMessage())
{
// bad syntax
return;
}
if (COMMAND_REGEX.IsMatch(message.Message))
{
Match m = COMMAND_REGEX.Match(message.Message);
string cmd = m.Groups[1].Value;
if (cmd.Equals("about"))
{
if (m.Groups[2].Value == null || m.Groups[2].Value.Equals(""))
{
message.SendChat("Need context");
}
string markov = MarkovDatabaseAdapter.MarkovFind(m.Groups[2].Value, m.Groups[3].Value);
if (markov == null || markov.Equals(""))
{
message.SendChat("I can't :(");
}
else
{
message.SendChat(markov);
}
}
}
}
示例3: HandleCommand
public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
{
var delta = DateTime.Now - BEGIN;
var seconds = delta.Seconds.ToString("n0");
var minutes = Math.Floor(delta.TotalMinutes).ToString("n0");
var hours = Math.Floor(delta.TotalHours).ToString("n0");
var days = Math.Floor(delta.TotalDays).ToString("n0");
string reply = "";
if (!seconds.Equals("0"))
{
if (minutes.Equals("1"))
{
reply = seconds + " second.";
}
else
{
reply = seconds + " seconds.";
}
}
if (!minutes.Equals("0"))
{
if (minutes.Equals("1"))
{
reply = minutes + " minute, " + reply;
}
else
{
reply = minutes + " minutes, " + reply;
}
}
if (!hours.Equals("0"))
{
if (hours.Equals("1"))
{
reply = hours + " hour, " + reply;
}
else
{
reply = hours + " hours, " + reply;
}
}
if (!days.Equals("0"))
{
if (days.Equals("1"))
{
reply = days + " day, " + reply;
}
else
{
reply = days + " days, " + reply;
}
}
msg.SendChat("Current uptime: " + reply);
}
示例4: HandleCommand
public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
{
if (!msg.HasMessage())
{
// oh no
return;
}
string nick = msg.Message.ToLower().Split(new char[] { ' ' }, 2)[0];
string lastSeenEvent = Database.GetKeyValue(server, "lastseen.event." + nick);
if (lastSeenEvent == null)
{
msg.SendChat("Have not seen " + nick);
}
else
{
TimeSpan t = TimeSpan.FromMilliseconds(Environment.TickCount - long.Parse(Database.GetKeyValue(msg.Server, "lastseen.time." + nick)));
string answer = string.Format("{0:D2} hours, {1:D2} minutes, {2:D2} seconds",
t.Hours,
t.Minutes,
t.Seconds);
msg.SendChat(string.Format("Last seen {0}: {1} ago, {2}", nick, answer, lastSeenEvent));
}
}
示例5: Handle
public void Handle(IncomingMessage msg)
{
string[] parts = msg.Message.Split(' ');
if (parts.Length == 4)
{
string text = msg.Message.Substring(msg.Message.IndexOf(parts[1]));
parts = text.Split(' ');
string user = parts[1];
string pass = parts[2];
UserAccess found = Database.AuthenticateUser(user, pass);
if (found != UserAccess.ANYONE)
{
//save here
msg.Server.Users[msg.Host] = found;
msg.SendChat("Thank you for authenticating, you have been granted " + found + " access.");
Configuration.Save(msg.Server);
}
}
else
{
msg.SendChat("To login: login <username> <password>");
}
}
示例6: Handle
public void Handle(IncomingMessage msg)
{
if (!msg.IsDestChannel() || !msg.HasMessage())
{
return;
}
if (SED_REGEX.IsMatch(msg.Message))
{
string lastmessage = Database.GetKeyValue(msg.Server, LASTMESSAGE_PREFIX + msg.Sender);
if (lastmessage == null || lastmessage.Equals(""))
{
// oh no
return;
}
string reply;
Match m = SED_REGEX.Match(msg.Message);
if (m.Groups[3] == null || m.Groups[3].Value.Equals(""))
{
reply = ReplaceFirst(lastmessage, m.Groups[1].Value, m.Groups[2].Value);
}
else if (m.Groups[3] != null && m.Groups[3].Value.Equals("g"))
{
reply = lastmessage.Replace(m.Groups[1].Value, m.Groups[2].Value);
}
else
{
msg.SendChat(msg.Sender + ": You did something wrong...");
return;
}
msg.SendChat(msg.Sender + " meant: " + reply);
}
else
{
Database.SetKeyValue(msg.Server, LASTMESSAGE_PREFIX + msg.Sender, msg.Message);
}
}
示例7: HandleCommand
public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
{
if (msg.HasMessage())
{
string channel = msg.Message;
string partMessage = "Bye!";
if (command.Equals("part"))
{
string[] parts;
if (msg.Message.Contains(" "))
{
parts = msg.Message.Split(new char[] { ' ' }, 2);
}
else
{
parts = new string[] { msg.Message };
}
if (parts.Length > 1)
{
if (parts[0].StartsWith("#"))
{
channel = parts[0];
partMessage = parts[1];
}
else
{
partMessage = msg.Message;
}
}
server.PartChannel(channel, partMessage);
}
else
{
server.JoinChannel(msg.Message);
}
}
else
{
msg.SendChat(Help());
}
}
示例8: HandleCommand
public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
{
try
{
string location;
if (!msg.HasMessage())
{
location = Database.GetKeyValue(msg.Server, "weather.lastlocation." + msg.Sender);
if (location == null)
{
msg.SendChat(msg.Sender + ": No previous location stored");
return;
}
}
else
{
location = msg.Message;
Database.SetKeyValue(msg.Server, "weather.lastlocation." + msg.Sender, location);
}
long lastquery = -1;
try
{
lastquery = long.Parse(Database.GetKeyValue(msg.Server, "weather.lastquery." + location));
}
catch (Exception)
{
lastquery = -1;
}
if (lastquery > 0 && Environment.TickCount - lastquery < TIMEOUT)
{
string lastdata = Database.GetKeyValue(msg.Server, "weather.lastdata." + location);
if (lastdata != null && !lastdata.Equals(""))
{
msg.SendChat(msg.Sender + ": " + lastdata);
}
else
{
// oh no
}
}
else
{
string location_encoded = Uri.EscapeUriString(location);
Database.SetKeyValue(msg.Server, "weather.lastquery." + location, Environment.TickCount);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(WEATHER_URL + location_encoded);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string responseContent;
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
responseContent = streamReader.ReadToEnd();
}
JObject json = JObject.Parse(responseContent);
Database.SetKeyValue(msg.Server, "weather.lastquery." + location, Environment.TickCount);
JToken list = json["list"][0];
StringBuilder w = new StringBuilder("Weather for " + list["name"].ToString() + ", " + list["sys"]["country"].ToString() + ", ");
JToken weather = list["weather"][0];
string description = weather["description"].ToString();
if (description != null && !description.Equals(""))
{
w.Append(description).Append(", ");
}
JToken main = list["main"]; JToken wind = list["wind"];
w.Append(string.Format("Temp {0}c (min {1}c/max {2}c), {3}% Humidity, {4} hPa, {5}% Cloudy, Wind Speed {6}m/s",
main["temp"].ToString(),
main["temp_min"].ToString(),
main["temp_max"].ToString(),
main["humidity"].ToString(),
main["pressure"].ToString(),
list["clouds"]["all"].ToString(),
wind["speed"].ToString()));
JToken windGust = wind["gust"];
if (windGust != null)
{
w.Append(string.Format(" (gusting {0}m/s)", windGust.ToString()));
}
string formatted = w.ToString();
Database.SetKeyValue(msg.Server, "weather.lastdata." + location, formatted);
msg.SendChat(msg.Sender + ": " + formatted);
}
}
catch (Exception e)
{
Console.Write(e);
}
}
示例9: HandleCommand
public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
{
if (!msg.HasMessage())
{
msg.SendChat(Help());
return;
}
string term = msg.Message;
long lastquery;
try
{
lastquery = long.Parse(Database.GetKeyValue(msg.Server, LASTQUERY_PREFIX + term));
}
catch (Exception)
{
lastquery = -1;
}
if (lastquery > 0 && Environment.TickCount - lastquery < TIMEOUT)
{
string lastdata = Database.GetKeyValue(msg.Server, LASTRESULT_PREFIX + term);
if (lastdata != null && !lastdata.Equals(""))
{
msg.SendChat(msg.Sender + ": " + lastdata);
}
else
{
msg.SendChat(string.Format("{0}: There was an error last time retrieving the definition for {1}, please try again in {2} minute(s)", msg.Sender, term,
TimeSpan.FromMilliseconds(TIMEOUT - (Environment.TickCount - lastquery)).Minutes));
}
}
else
{
string term_encoded;
try
{
term_encoded = Uri.EscapeUriString(term);
}
catch (Exception)
{
msg.SendChat(msg.Sender + ": Error parsing location," + msg.Message);
return;
}
Database.SetKeyValue(msg.Server, LASTQUERY_PREFIX + term, Environment.TickCount);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URBAN_URL + term_encoded);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string responseContent;
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
responseContent = streamReader.ReadToEnd();
}
JObject json = JObject.Parse(responseContent);
StringBuilder definition = new StringBuilder("Urban definition of `" + term + "`: ");
try
{
definition.Append(json["list"][0]["definition"].ToString());
}
catch (Exception)
{
msg.SendChat(msg.Sender + ": Error parsing urban data for, " + msg.Message);
return;
}
string formatted = definition.ToString();
Database.SetKeyValue(msg.Server, LASTRESULT_PREFIX + term, formatted);
msg.SendChat(msg.Sender + ": " + formatted);
}
}
示例10: HandleCommand
public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
{
int i = new Random().Next(0,sayings.Length-1);
string saying = sayings[i];
msg.SendChat(saying);
}