/*/ Constructors /*/ /// <summary> /// Initializes a new instance of the <see cref="IrcBot"/> class. /// </summary> /// <param name="juvoClient">Host.</param> /// <param name="ircClient">IRC client.</param> /// <param name="config">IRC configuration.</param> /// <param name="logManager">Log manager.</param> public IrcBot(IJuvoClient juvoClient, IIrcClient ircClient, IrcConfigConnection config, ILogManager?logManager = null) { this.config = config; this.host = juvoClient; this.logManager = logManager; this.client = ircClient; this.log = logManager?.GetLogger(typeof(IrcBot)); this.client.Network = IrcClient.LookupNetwork(this.config.Network ?? string.Empty); this.client.NickName = config.Nickname ?? throw new Exception("Nickname is missing from configuration"); this.client.NickNameAlt = config.NicknameAlt ?? $"{config.Nickname}-"; this.client.RealName = config.RealName ?? string.Empty; this.client.Username = config.Ident ?? config.Nickname.ToLowerInvariant(); this.client.ChannelJoined += this.Client_ChannelJoined; this.client.ChannelMessage += this.Client_ChannelMessage; this.client.ChannelModeChanged += this.Client_ChannelModeChanged; this.client.ChannelParted += this.Client_ChannelParted; this.client.Connected += this.Client_Connected; this.client.Disconnected += this.Client_Disconnected; this.client.HostHidden += this.Client_HostHidden; this.client.MessageReceived += this.Client_MessageReceived; this.client.PrivateMessage += this.Client_PrivateMessage; this.client.UserModeChanged += this.Client_UserModeChanged; this.client.UserQuit += this.Client_UserQuit; this.commandToken = config.CommandToken ?? DefaultCommandToken; }
/// <inheritdoc /> public IIrcBot Create(IrcConfigConnection config, IServiceProvider services, IJuvoClient host) { var bot = new IrcBot( host, services.GetService <IIrcClient>(), config, services.GetService <ILogManager>()); return(bot); }
public async Task <IBotCommand> Execute(IBotCommand cmd, IJuvoClient client) { var term = string.Join(' ', cmd.RequestText.Split(' ').Skip(1).ToArray()); var document = await this.context.OpenAsync($"{BingUri}{term}"); var cell = document.Body.SelectSingleNode(PathToDef); cmd.ResponseText = $"{term}: {cell.TextContent}"; return(cmd); }
/*/ Constructors /*/ /// <summary> /// Initializes a new instance of the <see cref="SlackBot"/> class. /// </summary> /// <param name="host">Host.</param> /// <param name="slackClient">Slack client.</param> /// <param name="config">Configuration to use.</param> /// <param name="logManager">Log manager.</param> public SlackBot(IJuvoClient host, ISlackClient slackClient, SlackConfigConnection config, ILogManager?logManager = null) { this.host = host; this.config = config; this.logManager = logManager; this.log = this.logManager?.GetLogger(typeof(SlackBot)); this.random = new Random(DateTime.Now.Millisecond * DateTime.Now.Second); this.slackClient = slackClient ?? throw new ArgumentNullException(nameof(slackClient)); this.slackClient.Initialize(config.Token); this.slackClient.MessageReceived += this.SlackClient_MessageReceived; }
public async Task <IBotCommand> Execute(IBotCommand cmd, IJuvoClient juvo) { var cmdParts = cmd.RequestText.Split(' '); var symbol = cmdParts[1].ToUpperInvariant(); try { using var document = await this.context.OpenAsync($"{YahooQuoteUri}{symbol}"); if (document.StatusCode != HttpStatusCode.OK) { cmd.ResponseText = "Could not retrieve quote"; return(cmd); } var header = document.Body.SelectSingleNode($"{XRoot}/div[2]/div[1]/div[1]/h1"); var mkprice = document.Body.SelectSingleNode($"{XRoot}/div[3]/div[1]/div/span[1]"); var mkchange = document.Body.SelectSingleNode($"{XRoot}/div[3]/div[1]/div/span[2]"); var mkasof = document.Body.SelectSingleNode($"{XRoot}/div[3]/div[1]/div/div/span"); var ahprice = document.Body.SelectSingleNode($"{XRoot}/div[3]/div[1]/p/span[1]"); var ahchange = document.Body.SelectSingleNode($"{XRoot}/div[3]/div[1]/p/span[2]/span"); var ahasof = document.Body.SelectSingleNode($"{XRoot}/div[3]/div[1]/p/span[3]"); cmd.ResponseText = $"{header.TextContent}: {mkprice.TextContent} {mkchange.TextContent} [{mkasof.TextContent}]"; if (ahprice is INode) { cmd.ResponseText += $" After/Pre: {ahprice.TextContent} {ahchange.TextContent} [{ahasof.TextContent}]"; } } catch (JsonReaderException jsonException) { juvo.Log(LogLevel.Error, "Error while parsing/reading json", jsonException); cmd.ResponseText = "An error occurred while parsing the response."; } return(cmd); }
/*/ Constructors /*/ /// <summary> /// Initializes a new instance of the <see cref="DiscordBot"/> class. /// </summary> /// <param name="discordClient">Discord client.</param> /// <param name="config">Configuration to use during initialization.</param> /// <param name="juvoClient">Host.</param> /// <param name="logManager">Log manager.</param> public DiscordBot(IDiscordClient discordClient, DiscordConfigConnection config, IJuvoClient juvoClient, ILogManager?logManager = null) { this.config = config ?? throw new ArgumentNullException(nameof(config)); this.host = juvoClient ?? throw new ArgumentNullException(nameof(juvoClient)); this.logManager = logManager; this.log = logManager?.GetLogger(typeof(DiscordBot)); if (this.config.AuthToken is null) { throw new InvalidOperationException("Configuration is missing Auth Token"); } this.discordClient = discordClient ?? throw new ArgumentNullException(nameof(discordClient)); this.discordClient.Initialize(new DiscordClientOptions { AuthToken = this.config.AuthToken, IsBot = true }); this.discordClient.Disconnected += this.DiscordClient_Disconnected; this.discordClient.ReadyReceived += this.DiscordClient_ReadyReceived; }
public async Task <IBotCommand> Execute(IBotCommand cmd, IJuvoClient client) { cmd.ResponseText = $"Received '{cmd.RequestText}' @ {DateTime.Now}"; return(await Task.FromResult(cmd)); }
public Task <IBotCommand> Execute(IBotCommand cmd, IJuvoClient client) { try { var cmdParts = cmd.RequestText.Split(' '); switch (cmdParts[0].ToLowerInvariant()) { case "abs": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: abs <value>"; } cmd.ResponseText = $"> {this.Abs(cmdParts[1])}"; break; } case "acos": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: acos <value>"; } cmd.ResponseText = $"> {this.Acos(cmdParts[1])}"; break; } case "asin": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: asin <value>"; } cmd.ResponseText = $"> {this.Asin(cmdParts[1])}"; break; } case "atan": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: atan <value>"; } cmd.ResponseText = $"> {this.Atan(cmdParts[1])}"; break; } case "atan2": { if (cmdParts.Length < 3) { cmd.ResponseText = "USAGE: atan2 <y> <x>"; } cmd.ResponseText = $"> {this.Atan2(cmdParts[1], cmdParts[2])}"; break; } case "atanh": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: atanh <value>"; } cmd.ResponseText = $"> {this.Atanh(cmdParts[1])}"; break; } case "cbrt": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: cbrt <value>"; } cmd.ResponseText = $"> {this.Cbrt(cmdParts[1])}"; break; } case "cos": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: cos <value>"; } cmd.ResponseText = $"> {this.Cos(cmdParts[1])}"; break; } case "cosh": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: cosh <value>"; } cmd.ResponseText = $"> {this.Cosh(cmdParts[1])}"; break; } case "log": { if (cmdParts.Length < 3) { cmd.ResponseText = "USAGE: log <value> [base: e]"; } cmd.ResponseText = $"> {this.Log(cmdParts[1], cmdParts.Length > 2 ? cmdParts[2] : string.Empty)}"; break; } case "pow": { if (cmdParts.Length < 3) { cmd.ResponseText = "USAGE: pow <x> <y>"; } cmd.ResponseText = $"> {this.Pow(cmdParts[1], cmdParts[2])}"; break; } case "sin": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: sin <value>"; } cmd.ResponseText = $"> {this.Sin(cmdParts[1])}"; break; } case "sinh": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: sinh <value>"; } cmd.ResponseText = $"> {this.Sinh(cmdParts[1])}"; break; } case "sqrt": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: sqrt <value>"; } cmd.ResponseText = $"> {this.Sqrt(cmdParts[1])}"; break; } case "tan": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: tan <value>"; } cmd.ResponseText = $"> {this.Tan(cmdParts[1])}"; break; } case "tanh": { if (cmdParts.Length < 2) { cmd.ResponseText = "USAGE: tanh <value>"; } cmd.ResponseText = $"> {this.Tanh(cmdParts[1])}"; break; } } } catch (ArgumentException exc) { cmd.ResponseText = $"! {exc.Message}"; } return(Task.FromResult(cmd)); }
public Task <IBotCommand> Execute(IBotCommand cmd, IJuvoClient client) { cmd.ResponseText = "Hello from example plugin!"; return(Task.FromResult(cmd)); }
/// <summary> /// Initializes a new instance of the <see cref="Program"/> class. /// </summary> /// <param name="juvoClient">Client to use.</param> public Program(IJuvoClient juvoClient) { this.juvoClient = juvoClient ?? throw new ArgumentNullException(nameof(juvoClient)); }