public async Task <string> GenerateMessage(int wordLimit = 50) => await Task.Run(() => { if (MarkovData[MarkovData.start].Count == 0) { return("Markov Chain database is empty, Try saying some things!"); } StringBuilder builder = new StringBuilder(); string lastWord = MarkovData.start; for (int i = 0; (builder.Length < MaxGenLength) || (i > wordLimit); i++) { List <string> words = MarkovData[lastWord]; if (words.Count == 0) { i--; continue; // This should never happen } lastWord = words[LilGUtil.RandInt(0, words.Count - 1)]; if (lastWord == MarkovData.end) { break; } builder.Append(lastWord).Append(" "); } return(builder.ToString()); });
public async Task HandleCommand(IListener listener, IRespondable respondTo, IList <string> args, LinkedMessage e) { SendOptions opts = new SendOptions(); try{ opts.Parse(args); string msg = opts.Parameters.Count > 0 ? LilGUtil.ArgJoiner(opts.Parameters.ToArray()) : opts.Parameters[0]; if (opts.Raw) { LinkedIrcMessage message = (LinkedIrcMessage)e; message.Client.SendRawMessage(msg); return; } if (opts.channelId != 0) { DiscordChannel channel = await Program.Config.DiscordSocketClient.GetChannelAsync(opts.channelId); await channel.SendMessageAsync(msg); return; } if (opts.channel != null) { LinkedIrcMessage message = (LinkedIrcMessage)e; if (message.Client.Channels.Contains(opts.channel)) { message.Client.SendMessage(msg, opts.channel); } } } catch (GetOptException) { await Help(listener, respondTo, args, e); } }
public async Task HandleCommand(IListener listener, IRespondable respondTo, IList <string> args, LinkedMessage e) { var opts = new ReplOptions(); try{ opts.Parse(args); string code; if (opts.Parameters.Count > 1) { code = LilGUtil.ArgJoiner(opts.Parameters.ToArray()); } else { code = opts.Parameters[0]; } Globals.e = e; Globals.args = args; Globals.listener = listener; Globals.respondTo = respondTo; Globals.server = e.server; Globals.channel = e.channel; Globals.author = e.author; Task <object> task = CSharpScriptEngine.Execute(code, Globals); await respondTo.respond((await task).ToString(), e.author); } catch (GetOptException) { await Help(listener, respondTo, args, e); } }
public async Task onMessage(IListener listener, IRespondable respondTo, LinkedMessage e) { if (!e.message.StartsWith(termChar)) { return; } if (!LilGUtil.CheckIfOwner(e)) { return; } bool?connected = SshClient?.IsConnected; if ((connected == null) || (bool)!connected) { await respondTo.respond("Need to connect to a client first"); return; } using (SshCommand command = SshClient.RunCommand(e.message.Substring(1))){ await respondTo.respond(command.Result); } }
public async Task HandleCommand(IListener listener, IRespondable respondTo, IList <string> args, LinkedMessage e) { int choice = LilGUtil.RandInt(1, 20); string response = ""; switch (choice) { case 1: response = "It is certain"; break; case 2: response = "It is decidedly so"; break; case 3: response = "Without a doubt"; break; case 4: response = "Yes - definitely"; break; case 5: response = "You may rely on it"; break; case 6: response = "As I see it, yes"; break; case 7: response = "Most likely"; break; case 8: response = "Outlook good"; break; case 9: response = "Signs point to yes"; break; case 10: response = "Yes"; break; case 11: response = "Reply hazy, try again"; break; case 12: response = "Ask again later"; break; case 13: response = "Better not tell you now"; break; case 14: response = "Cannot predict now"; break; case 15: response = "Concentrate and ask again"; break; case 16: response = "Don't count on it"; break; case 17: response = "My reply is no"; break; case 18: response = "My sources say no"; break; case 19: response = "Outlook not so good"; break; case 20: response = "Very doubtful"; break; } await respondTo.respond(response, e.author); }
public async Task <bool> CommandHandler(PrivateMessageEventArgs e) { if (e.PrivateMessage.User.Hostmask == IrcSelf.Hostmask) { return(false); } string message = e.PrivateMessage.Message; string messageLower = message.ToLower(); string[] args = message.SplitMessage(); IRespondable respondTo; if (e.PrivateMessage.IsChannelMessage) { respondTo = (LinkedIrcChannel)e.PrivateMessage.Channel; } else { respondTo = (LinkedIrcUser)e.PrivateMessage.User; } string first = args[0].ToLower(); bool commandByName = first.StartsWith(IrcSelf.Nick.ToLower()); bool commandByPrefix = messageLower.StartsWithAny(Config.CommandPrefixes); if (commandByName || commandByPrefix) { string command = null; int offset = 1; if (commandByName) { if (args.Length < 2) { return(false); } command = args[1]; offset = 2; } if (commandByPrefix) { foreach (string prefix in Config.CommandPrefixes) { if (messageLower.StartsWith(prefix)) { if (prefix.EndsWith(" ")) { if (args.Length < 2) { return(false); } command = args[1]; offset = 2; break; } command = args[0].Substring(prefix.Length); break; } } } if (command == null) { return(false); } if (Program.CommandList.ContainsCommand(command)) { LinkedIrcMessage linkedMessage = e; if (!LilGUtil.CheckPermission(command, linkedMessage)) { await respondTo.respond($"Sorry, you don't have the permission to run {command}"); return(true); } ICommand icommand = Program.CommandList[command]; ArraySegment <string> segment = new ArraySegment <string>(args, offset, args.Length - offset); try{ await icommand.HandleCommand(this, respondTo, segment, (LinkedIrcMessage)e); } catch (Exception ex) { Logger.Error(ex, "Problem processing command: \n{0}", ex.StackTrace); await respondTo.respond($"Sorry there was a problem processing the command: {ex.Message}"); return(true); } return(true); } } return(false); }
public async Task <bool> CommandHandler(MessageCreateEventArgs e) { if (e.Author == e.Client.CurrentUser) { return(false); } string message = e.Message.Content; string[] args = message.SplitMessage(); IRespondable respondTo; if (e.Channel != null) { respondTo = (LinkedDiscordChannel)e.Channel; } else { respondTo = (LinkedDiscordUser)e.Author; } bool commandByName = args[0].StartsWith(e.Client.CurrentUser.Mention) || args[0].StartsWith(e.Guild.CurrentMember.DisplayName) || args[0].StartsWith(e.Client.CurrentUser.Username); bool commandByPrefix = message.StartsWithAny(Config.CommandPrefixes); if (commandByName || commandByPrefix) { string command = null; int offset = 1; if (commandByName) { if (args.Length < 2) { return(false); } command = args[1]; offset = 2; } if (commandByPrefix) { foreach (string prefix in Config.CommandPrefixes) { if (message.StartsWith(prefix)) { if (prefix.EndsWith(" ")) { if (args.Length < 2) { return(false); } command = args[1]; offset = 2; break; } command = args[0].Substring(prefix.Length); break; } } } if (command == null) { return(false); } if (Program.CommandList.ContainsCommand(command)) { LinkedDiscordMessage linkedMessage = e; if (!LilGUtil.CheckPermission(command, linkedMessage)) { await respondTo.respond($"Sorry, you don't have the permission to run {command}"); return(true); } ArraySegment <string> segment = new ArraySegment <string>(args, offset, args.Length - offset); try{ await Program.CommandList[command].HandleCommand(this, respondTo, segment, (LinkedDiscordMessage)e); } catch (Exception ex) { Logger.Error(ex, "Problem processing command: \n{0}", ex); await respondTo.respond($"Sorry there was a problem processing the command: {ex.Message}"); return(true); } return(true); } } return(false); }