本文整理汇总了C#中IMessageClient.ReplyTo方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageClient.ReplyTo方法的具体用法?C# IMessageClient.ReplyTo怎么用?C# IMessageClient.ReplyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessageClient
的用法示例。
在下文中一共展示了IMessageClient.ReplyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RollDice
public void RollDice(Message message, IMessageClient client, string sides)
{
var dice = new Random(DateTime.Now.Millisecond);
//default to typical 6 side die
int numSides = 6;
if (string.IsNullOrEmpty(sides) || int.TryParse(sides, out numSides))
{
if (numSides <= 0)
{
//negative number
var result = "I'm sorry, i will not roll a " + numSides.ToString() +
" sided dice without adult supervision. That would tear a hole in the universe...";
client.ReplyTo(message, result);
Thread.Sleep(5000);
client.ReplyTo(message, "No... you don't qualify as an adult");
}
else
{
//good number
var result = "You rolled a " + dice.Next(1, numSides + 1) + " on a " + numSides.ToString() + " sided dice";
client.ReplyTo(message, result);
}
}
else
{
//non number, or too large a number
var result = "I can't roll a " + sides + " I am but a meager .net bot";
client.ReplyTo(message, result);
}
}
示例2: XkcdMe
public void XkcdMe(Message message, IMessageClient client, string number)
{
IRestClient jsonClient = GetJsonServiceClient("http://xkcd.com");
var result = new RootObject();
string jsonResponse;
try
{
jsonResponse = (string.IsNullOrEmpty(number) || number == "xkcd me")
? jsonClient.Get<string>("/info.0.json")
: jsonClient.Get<string>(string.Format("/{0}/info.0.json", number));
}
catch (Exception)
{
jsonResponse = jsonClient.Get<string>("/1/info.0.json");
}
result.Value = JsonObject.Parse(jsonResponse);
string imgUrl = result.Value.Child("img").Replace("\\", "");
string altText = result.Value.Child("alt");
//Reply with two messages back to back
client.ReplyTo(message, imgUrl);
client.ReplyTo(message, altText);
}
示例3: SearchStackOverflow
public void SearchStackOverflow(Message message, IMessageClient client, string query)
{
try
{
var authCode = Robot.GetSetting<string>("StackappsApiKey");
if (string.IsNullOrEmpty(authCode))
throw new ArgumentException("Please supply the StackappsApiKey");
var result = GetGZipedJsonServiceClient(string.Format("http://api.stackoverflow.com/1.1/search?intitle={0}&key={1}",
Uri.EscapeDataString(query),
Uri.EscapeDataString(authCode)))
.Get<SearchResult>("/");
if (result.Questions.Any())
{
client.ReplyTo(message, string.Format("Top 5 Search results for: {0}", query));
foreach (Question question in result.Questions.OrderByDescending(q => q.answer_count).Take(5))
{
client.ReplyTo(message, string.Format("{0} responses to: {1} {2}", question.answer_count, question.title, "http://stackoverflow.com" + question.question_answers_url));
}
}
else
{
client.ReplyTo(message, string.Format("No results found for {0}", query));
}
}
catch (Exception ex)
{
EventLog.WriteEntry("NBot-Sosearch", ex.ToString());
client.ReplyTo(message, "Error in searching Stack Overflow.");
}
}
示例4: Translate
private void Translate(Message message, IMessageClient client, string textToTranslate)
{
try
{
var result = GetJsonServiceClient(string.Format("http://isithackday.com/arrpi.php?text={0}&format=json", UrlEncode(textToTranslate)))
.Get<string>("pirate");
client.ReplyTo(message, result);
}
catch (Exception ex)
{
EventLog.WriteEntry("NBot-PirateTranslator", ex.ToString());
client.ReplyTo(message, "PirateTranslator crashed!");
}
}
示例5: Recieve
public void Recieve(Message message, IMessageClient client)
{
IRestClient httpClient = GetJsonServiceClient("http://facepalm.org");
var response = httpClient.Get<HttpWebResponse>("/img.php");
var imageUrl = response.ResponseUri.AbsoluteUri;
client.ReplyTo(message, imageUrl);
}
示例6: SwansonMe
public void SwansonMe(Message message, IMessageClient client)
{
var httpclient = GetJsonServiceClient("http://ronsays.tumblr.com");
var html = httpclient.Get<string>("/random");
var linkMatch = Regex.Match(html, "<div class=\"stat-media-wrapper\"><a href=\"http://ronsays.tumblr.com/image/(\\d+)\"><img\\ssrc=\"(.*)\"\\salt");
client.ReplyTo(message, linkMatch.Groups[2].Value);
}
示例7: DoExcuseMe
public void DoExcuseMe(Message mesage, IMessageClient client)
{
IEntity user = client.GetUser(mesage.UserId);
IRestClient httpClient = GetJsonServiceClient("http://developerexcuses.com/");
var result = httpClient.Get<string>("/");
Match matches = Regex.Match(result, "<a href=\"/\" .*>(.*)</a>");
string excuse = matches.Groups[1].Value;
client.ReplyTo(mesage, string.Format("{0}, your excuse is \"{1}\".", user.Name, excuse));
}
示例8: FindMemeGenerator
public void FindMemeGenerator(Message message, IMessageClient client, string url)
{
IRestClient httpClient =
GetJsonServiceClient(
string.Format(
"http://version1.api.memegenerator.net/Generator_Select_ByUrlNameOrGeneratorID?generatorID=&urlName={0}",
url));
var response = httpClient.Get<string>("");
client.ReplyTo(message, response);
}
示例9: CreateJoinMe
public void CreateJoinMe(Message message, IMessageClient client)
{
var authCode = Robot.GetSetting<string>("JoinMeAuthCode");
if (string.IsNullOrEmpty(authCode))
{
throw new ArgumentException("Please set the JoinMeAuthCode.");
}
var result = GetJsonServiceClient(string.Format("https://secure.join.me/API/requestCode?authCode={0}", authCode))
.Get<String>("/");
string[] stuff = result.Split(new[] { ':', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
string code = stuff[2].Trim();
string ticket = stuff[4].Trim();
string presenter = string.Format("Presenter: https://secure.join.me/download.aspx?code={0}&ticket={1}", code, ticket);
string viewer = string.Format("Viewer: http://join.me/{0}", code);
client.ReplyTo(message, presenter);
client.ReplyTo(message, viewer);
}
示例10: PingMe
public void PingMe(Message message, IMessageClient client, string location)
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "ping.exe";
startInfo.Arguments = location;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
var process = Process.Start(startInfo);
process.WaitForExit(5000);
var result = process.StandardOutput.ReadToEnd();
client.ReplyTo(message, result);
}
示例11: DoIsItDownForYou
public void DoIsItDownForYou(Message message, IMessageClient client, string site)
{
try
{
IRestClient jsonClient = GetJsonServiceClient(DownForMeSite);
var result = jsonClient.Get<string>(site);
Match match = Regex.Match(result, SiteIsUpReges);
client.ReplyTo(message, match.Success ? string.Format("It's just you. {0} is up for me.", site) : string.Format("Oh no {0} is down for me too!!!!! *PANIC*", site));
}
catch (Exception e)
{
client.Send("Oh no I am Down!!! *UberPanic*", message.RoomId);
}
}
示例12: ChuckNorrisJoke
public void ChuckNorrisJoke(Message message, IMessageClient client, string name)
{
IRestClient jsonClient = GetJsonServiceClient("http://api.icndb.com/jokes/");
RootObject result;
if (!string.IsNullOrEmpty(name))
{
result = jsonClient.Get<string>("random?firstName=" + name + "&lastName=").FromJson<RootObject>();
}
else
{
result = jsonClient.Get<string>("random").FromJson<RootObject>();
}
client.ReplyTo(message, result.Value.Joke);
}
示例13: PluginHelp
public void PluginHelp(Message message, IMessageClient client, string plugin)
{
string ouputMessage = string.Format("Commands for {0}:", plugin);
IEnumerable<List<Command>> helpInformationCommands = _helpInformation.Where(hi => hi.Plugin.ToLower() == plugin.ToLower()).Select(hi => hi.Commands);
foreach (var commands in _helpInformation.Where(hi => hi.Plugin.ToLower() == plugin.ToLower()).Select(hi => hi.Commands))
{
foreach (Command command in commands)
{
ouputMessage += "\n" + string.Format("Command Syntax: {0}\nDescription: {1}\nExample: {2}\n", command.Syntax, command.Description, command.Example);
}
}
client.ReplyTo(message, helpInformationCommands.Any()
? ouputMessage
: string.Format("Plugin '{0}' not found.", plugin));
}
示例14: HandlePowerShellCommand
public void HandlePowerShellCommand(Message message, IMessageClient client, string command, string parameters)
{
if (_commands.ContainsKey(command))
{
var filePath = _commands[command];
var scriptParameters = string.IsNullOrEmpty(parameters) ? string.Empty : parameters;
var startInfo = new ProcessStartInfo();
startInfo.FileName = "powershell.exe";
startInfo.Arguments = string.Format("-File {0} {1}", filePath, scriptParameters);
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
var process = Process.Start(startInfo);
process.WaitForExit(5000);
var result = process.StandardOutput.ReadToEnd();
client.ReplyTo(message, result);
}
}
示例15: HandleGetStatus
public void HandleGetStatus(Message message, IMessageClient client, IBrain brain, string userName)
{
string result = userName;
bool needsAnd = false;
bool neverSeenThem = true;
if (brain.ContainsKey(LastCheckinKey(userName)))
{
result += " last checked in at " + brain.GetValue(LastCheckinKey(userName));
neverSeenThem = false;
needsAnd = true;
}
if (brain.ContainsKey(LastCheckoutKey(userName)))
{
if (needsAnd)
{
result += ",";
}
result += " last checked out at " + brain.GetValue(LastCheckoutKey(userName));
neverSeenThem = false;
needsAnd = true;
}
if (brain.ContainsKey(LastSpokeKey(userName)))
{
if (needsAnd)
{
result += " and";
}
result += " last spoke at " + brain.GetValue(LastSpokeKey(userName));
neverSeenThem = false;
}
if (neverSeenThem)
{
result = "I ain't never seen " + userName + " come round these parts";
}
client.ReplyTo(message, result);
}