public virtual async void HandleMessage(FullMessage message) { if (TemporaryCommandHandlers.TryGetValue(message.Channel.ID, out TemporaryCommandHandler tempHandler)) { if (tempHandler.HandleMessage(message)) { // If the temporary handler reads a command, skip any other command handling Logger.LogInfo($"TempHandler handled command: {message.Content}\nIn channel: {message.Channel}"); return; } } if (ParseCommand(message, out var command, out var parameters)) { if (BotCommands.TryGetValue(command.ToLower(), out BotCommand botCommand)) { CommandInfo commandInfo = new CommandInfo() { Message = message, Command = command, Arguments = parameters, CommandHandler = this, }; TemporaryCommandHandlers.Remove(message.Channel.ID); botCommand.Execute(commandInfo, commandInfo.ApiClient); } else { await ApiClient.PostMessage($"There is no command for {command}", message.Channel.ID); } }
public override bool ParseIntent(CUIContext context, DateTime time, string input) { if (IsBotsContext) { if (BotCommands.Contains(input.ToLower())) { var cmd = input.ToLower(); switch (cmd) { case "leave": Controller.SetDefaultPrompt(); DispatchIntent(null, Menu); break; default: SayErrorLine($"No handler for command {cmd}."); break; } return(true); } else if (Int32.TryParse(input, out int result) && QuickReplies != null && (result - 1) < QuickReplies.Length) { DispatchBotInput(QuickReplies[result - 1]); } else { DispatchBotInput(input); } return(true); } else { return(base.ParseIntent(context, time, input)); } }
static void Main(string[] args) { //Channel you wish the bot to join string Channel = ""; bool BotRunning = true; string msg; //Starte new TcP Stream BotTcpStream stream = new BotTcpStream(); StreamReader recieveServerStream = new StreamReader(stream.GetCurrentStream()); StreamWriter sendToServer = new StreamWriter(stream.GetCurrentStream()); //Initialize Bot Bot Bot = new Bot(recieveServerStream, sendToServer); Bot.Login(); Bot.Join(Channel); BotCommands bCMD = new BotCommands(sendToServer, recieveServerStream); //Start bot loop while (BotRunning) { msg = recieveServerStream.ReadLine(); bCMD.ReadServerMessage(msg); bCMD.ReadChatCommand(msg); } }
public static async Task HunterDeath() { var hunter = Global.Game.PersonnagesList.Find(p => p.GetType() == typeof(Hunter)); var message = await hunter.ChannelT.SendMessageAsync(Global.Game.Texts.GameRoles.HunterDeathQuestion); foreach (var emoji in (await Global.Game.Guild.GetEmojisAsync()).ToList() .FindAll(emo => emo.Id != hunter.Emoji.Id)) { await message.CreateReactionAsync(emoji); } await Task.Delay(Global.Config.DayVoteTime); var target = (await BotCommands.GetVotes(message)).Voted(); await Global.Game.Kill(target); var embed = new DiscordEmbedBuilder { Title = $"{hunter.Me.Username} {Global.Game.Texts.Annoucement.PublicHunterMessage} {target.Username}", Color = Color.DeadColor }; await Global.Game.DiscordChannels[GameChannel.TownText].SendMessageAsync(embed: embed.Build()); }
public static async Task WolfVote() { Global.Game.NightTargets = new List <Personnage>(); var embed = new DiscordEmbedBuilder { Color = Color.PollColor, Title = Global.Game.Texts.Annoucement.NightlyWolfMessage }; var msg = await Global.Game.DiscordChannels[GameChannel.WolfText].SendMessageAsync(embed: embed.Build()); foreach (var personnage in Global.Game.PersonnagesList.FindAll(p => p.GetType() != typeof(Wolf) && p.Alive)) { await msg.CreateReactionAsync(personnage.Emoji); } await Task.Delay(Global.Config.DayVoteTime); var targetMember = (await BotCommands.GetVotes(msg)).Voted(); if (targetMember != null) { var targetPersonnage = Global.Game.PersonnagesList.Find(p => p.Me == targetMember); Global.Game.NightTargets.Add(targetPersonnage); } else { embed = new DiscordEmbedBuilder { Color = Color.InfoColor, Title = Global.Game.Texts.Polls.NoWolfKill }; await Global.Game.DiscordChannels[GameChannel.WolfText].SendMessageAsync(embed: embed.Build()); } }
private void TwitchClient_OnChatCommandReceived(object sender, OnChatCommandReceivedArgs e) { var command = e.Command.CommandText; if (BotCommands.Execute(e.Command.CommandText, e) > 0) { return; } if (e.Command.ChatMessage.DisplayName == "CodeRushed") { if (e.Command.CommandText == "Reset" && e.Command.ArgumentsAsString == "Fanfare") { ResetFanfares(); } if (e.Command.CommandText == "Fanfare") { string displayName = e.Command.ChatMessage.DisplayName; PlayFanfare(displayName); } } var scene = GetScene(command); if (scene != null) { ActivateSceneIfPermitted(scene, e.Command.ChatMessage.DisplayName, allViewers.GetUserLevel(e.Command.ChatMessage)); } //else // Whisper(e.Command.ChatMessage.Username, GetWhatMessage() + " Command not recognized: " + e.Command.CommandText); }
/// <summary> /// Send a list of available commands /// </summary> /// <returns></returns> private async Task DefaultCommand(Message message) { var list = BotCommands.GetCommands(); var result = "Available commands: \r\n"; result += string.Join("\r\n", list); await _botService.Client.SendTextMessageAsync(message.From.Id, result); }
public DiscordGatewayBot(string token) { this.token = new TokenResponse(true) { AccessToken = token }; commands = new BotCommands(this.token); Guilds = new BotGuildManager(this.token); }
public DiscordGatewayBot(TokenResponse token) { this.token = token; if (token.Type != TokenType.Bot) { token.Type = TokenType.Bot; } commands = new BotCommands(this.token); Guilds = new BotGuildManager(this.token); }
public TemporaryCommandHandler AddCommand(string name, Func<CommandInfo, Task> command) { try { BotCommands.Add(name, new BotCommand(command)); ParentCommandHandler.Logger.LogInfo($"{name}, {command}, {command?.Method?.ToString()}"); } catch(Exception ex) { ParentCommandHandler.Logger.LogException(ex); } return this; }
private string GetCityName(string message, BotCommands command) { switch (command) { case BotCommands.Weather: message = message.Replace("/weather", string.Empty).Trim(); return(message); case BotCommands.Forecast: message = message.Replace("/forecast", string.Empty).Trim(); return(message); } return(string.Empty); }
//private static string[] tokens = null; static void Main(string[] args) { Console.Title = "Open Sourced Discord Spammer//Bomber"; Console.WriteLine("Made by ElKoax and Xenith (Used some of his code cause ye)"); Directory.CreateDirectory("./files/"); Proxies.ScrapeProxies(); Proxies.ReadProxiesFile(); Tokens.ReadTokensFile(); Thread.Sleep(20000); for (; ;) { Console.WriteLine(""); Console.WriteLine("Type your command below."); string cmd = Console.ReadLine(); string[] cmdparams = cmd.Split(' '); switch (cmdparams[0].ToLower()) { case "join": File.WriteAllText("files/tokens.txt", new HttpClient().GetStringAsync("Upload some tokens and this will work! UwU!").Result); Console.WriteLine("Input the invite of the server you would like to join bot below:", ConsoleColor.Magenta); Console.WriteLine(">", ConsoleColor.Blue); //SetColor(ConsoleColor.White); string join_inv = Console.ReadLine(); // string join_p_inv = InviteFunctions.ParseInvite(join_inv); // if (InviteFunctions.CheckInvite(join_p_inv) == false) // { // Error($"The invite you have provided ({join_inv}) is invalid! Please try again with a valid invite."); // return; // } foreach (string token in Tokens.tokens) { new Thread(() => BotCommands.Join(token, join_inv)).Start(); } Thread.Sleep(50); break; case "raid": Console.WriteLine("im too lazy to write this lol,"); // Credits to Xenith for the command handler. break; } } }
private void TwitchClient_OnChatCommandReceived(object sender, OnChatCommandReceivedArgs e) { var command = e.Command.CommandText; if (BotCommands.Execute(e.Command.CommandText, e) > 0) { return; } var scene = GetScene(command); if (scene != null) { ActivateSceneIfPermitted(scene, e.Command.ChatMessage.DisplayName, allViewers.GetUserLevel(e.Command.ChatMessage)); } //else // Whisper(e.Command.ChatMessage.Username, GetWhatMessage() + " Command not recognized: " + e.Command.CommandText); }
/// <summary> /// Try find <see cref="text"/> in <see cref="BotCommands"/> and <see cref="CommandsAssociations"/>. /// </summary> /// <param name="text">Text of not accepted command.</param> /// <param name="command">User unique identifier.</param> protected bool IsTextContainCommand(string text, out string command) { if (CommandsAssociations.ContainsKey(text)) { command = CommandsAssociations[text]; return(true); } var lowerText = text.ToLower(); if (BotCommands.ContainsKey(lowerText)) { command = lowerText; return(true); } command = null; return(false); }
private async Task AddNewCommandStack(Message message, long idUser) { var command = BotCommands.GetCommandAction(_botService.Client, message.Text); var isExists = _botService.UserActions.Any(user => user.IdUser == idUser); if (command != null && !isExists) { _botService.UserActions.Add(new UserAction { Command = command, IdUser = message.From.Id }); await command.Action(message); return; } await DefaultCommand(message); }
public void LoadCommands(CommandService commandService) { var commands = commandService.GetCommands(); foreach (var c in commands) { try { // All commands are stored in lower case, bot commands are case insensitive BotCommands.Add(c.Key.ToLower(), new BotCommand(c.Value)); } catch (Exception ex) { Logger.LogException(ex); } } Logger.LogInfo($"{BotCommands.Count} commands loaded in CommandHandler ({commands.Count()} expected)."); }
protected override bool TryCustomMessageProcessing <TMessage>(TUserId userId, TMessage message, out IEnumerable <MessageAbstraction> messagesToSend) { messagesToSend = null; if (!CommandsGetters[typeof(TMessage)].Invoke(message, out var command)) { return(false); } if (BotCommands.TryGetValue(command, out var action)) { messagesToSend = action(message, userId); Logger?.LogInformation($"Accepted command \"{command}\" from user {userId}"); } else { messagesToSend = OnBadCommand(command, userId); } return(true); }
public virtual bool HandleMessage(FullMessage message) { if (ParseCommand(message, out var command, out var parameters)) { if (BotCommands.TryGetValue(command, out BotCommand botCommand)) { CommandInfo commandInfo = new CommandInfo() { Message = message, Command = command, Arguments = parameters, CommandHandler = ParentCommandHandler, }; botCommand.Execute(commandInfo, commandInfo.ApiClient); return true; } else { return false; } }
//protected override async void OnKeyDown(KeyRoutedEventArgs e) //{ // if (e.Key == VirtualKey.Enter) // { // // Check if CTRL or Shift is also pressed in addition to Enter key. // var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control); // var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift); // // If there is text and CTRL/Shift is not pressed, send message. Else allow new row. // if (!ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down) && !IsEmpty) // { // e.Handled = true; // await SendAsync(); // } // } // base.OnKeyDown(e); //} private async void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { if (args.VirtualKey == VirtualKey.Enter && FocusState != FocusState.Unfocused) { // Check if CTRL or Shift is also pressed in addition to Enter key. var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control); var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift); var key = Window.Current.CoreWindow.GetKeyState(args.VirtualKey); if (UsernameHints != null && ViewModel.UsernameHints != null) { var send = key.HasFlag(CoreVirtualKeyStates.Down) && !ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down); if (send) { AcceptsReturn = false; var container = UsernameHints.ContainerFromIndex(Math.Max(0, UsernameHints.SelectedIndex)) as ListViewItem; if (container != null) { var peer = new ListViewItemAutomationPeer(container); var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; invokeProv.Invoke(); } } else { AcceptsReturn = true; } return; } if (BotCommands != null && ViewModel.BotCommands != null) { var send = key.HasFlag(CoreVirtualKeyStates.Down) && !ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down); if (send) { AcceptsReturn = false; var container = BotCommands.ContainerFromIndex(Math.Max(0, BotCommands.SelectedIndex)) as ListViewItem; if (container != null) { var peer = new ListViewItemAutomationPeer(container); var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; invokeProv.Invoke(); } } else { AcceptsReturn = true; } return; } // If there is text and CTRL/Shift is not pressed, send message. Else allow new row. if (ApplicationSettings.Current.IsSendByEnterEnabled) { var send = key.HasFlag(CoreVirtualKeyStates.Down) && !ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down); if (send) { AcceptsReturn = false; await SendAsync(); } else { AcceptsReturn = true; } } else { var send = key.HasFlag(CoreVirtualKeyStates.Down) && ctrl.HasFlag(CoreVirtualKeyStates.Down) && !shift.HasFlag(CoreVirtualKeyStates.Down); if (send) { AcceptsReturn = false; await SendAsync(); } else { AcceptsReturn = true; } } } }