private void Tile_Click(object sender, RoutedEventArgs e) { if (Window == null) { Window = new CommandsGeneratorTemplate(this); Window.win = (Application.Current.MainWindow as IMainWindowCommands).AddWindow(Icon, Window, "命令生成器", this); Window.win.WindowClosed += Win_WindowClosed; } object content = null; string title = (sender as Tile).Title; switch (title) { case "基础命令": content = new BasicCommands(Window); break; case "服务器命令": content = new ServerCommands(Window); break; case "实体命令": content = new EntityCommands(Window); break; case "玩家命令": content = new PlayerCommands(Window); break; case "Json书": content = new Book(Window); break; case "告示牌": content = new Sign(Window); break; case "消息文本": content = new Tellraw(Window); break; case "显示标题": content = new Title(Window); break; case "记分板目标": content = new ScoreboardObjective(Window); break; case "记分板玩家": content = new ScoreboardPlayers(Window); break; case "记分板队伍": content = new ScoreboardTeam(Window); break; case "物品NBT": content = new ItemNBT(Window); break; case "实体NBT": content = new EntityNBT(Window); break; case "物品与生成": content = new GetElement(); break; case "检测与执行": content = new ExecuteAndDetect(); break; case "方块NBT/放置填充方块": content = new SetBlocks(Window); break; case "村民交易": content = new VillagerTrade(Window); break; case "刷怪笼": content = new MobSpawner(Window); break; case "烟花": content = new Firework(Window); break; case "旗帜/盾牌": content = new Banners(Window); break; case "药水/药水箭": content = new Potion(Window); break; case "盔甲架": content = new ArmorStand(Window); break; } Window.AddPage(title, content); }
public MainWindow() { InitializeComponent(); BotProgram.UploadCommands(BasicCommands.GetBasicCommands()); Menu menuWindow = new Menu(); Close(); }
private void OnFriendMsg(SteamFriends.FriendMsgCallback callback) { if (callback.EntryType == EChatEntryType.ChatMsg) { var sender = callback.Sender; Friend currentChatter = Chatters.FirstOrDefault(chatter => chatter.SteamID.AccountID == sender.AccountID); if (currentChatter == null) { currentChatter = new Friend() { WelcomedDate = DateTime.Now, ChatState = ChatState.NoInteraction, SteamID = sender, IsReceivingAdvInfo = false }; Chatters.Add(currentChatter); } TimeSpan timeSpan = DateTime.Now - currentChatter.WelcomedDate; if (timeSpan.Minutes >= 5) { currentChatter.ChatState = ChatState.NoInteraction; } string responseMessage = String.Empty; if (BasicCommands.ContainsKey(callback.Message)) { responseMessage = BasicCommands[callback.Message]; currentChatter.ChatState = ChatState.Welcomed; } else if (currentChatter.ChatState == ChatState.NoInteraction) { currentChatter.ChatState = ChatState.Welcomed; responseMessage = WelcomeMessage; } else if (currentChatter.ChatState == ChatState.Welcomed) { responseMessage = CommandNotFoundMessage; } SteamFriends.SendChatMessage(sender, EChatEntryType.ChatMsg, responseMessage); Console.WriteLine($"{SteamFriends.GetFriendPersonaName(sender)}: {callback.Message}"); Console.WriteLine($"BOT: {responseMessage}"); } }
static void Main(string[] args) { // Getting the secret to be used in the password section var builder = new ConfigurationBuilder() .AddUserSecrets <Program>() .Build(); var serviceProvider = builder.Providers.First(); if (!serviceProvider.TryGet("TwitchAccess:username", out var username)) { return; } if (!serviceProvider.TryGet("TwitchAccess:OAuth", out var password)) { return; } if (!serviceProvider.TryGet("TwitchAccess:channel", out var channel)) { return; } var client = new TwitchClient("irc.twitch.tv", 6667, username, password, channel); // Ping the server to prevent twitch disconnect your bot var botAlive = new Ping(client); botAlive.Start(); // Initial connection Interpreter.Init(client.ReadChatMessage()); BasicCommands commands = new BasicCommands(); // Message listener while (true) { var message = client.ReadChatMessage(); var msg = Interpreter.Chat(message); // listen to commands and respond var response = commands.CommandListener(msg); client.SendChatMessages(response); } Console.ReadKey(); }
private async Task HandleCommandAsync(SocketMessage messageParam) { // Don't process the command if it was a system message var message = messageParam as SocketUserMessage; if (message == null) { return; } // Create a number to track where the prefix ends and the command begins int argPos = 0; // Determine if the message is a command based on the prefix and make sure no bots trigger commands if (!(message.HasCharPrefix(Program.prefix, ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)) || message.Author.IsBot) { return; } // Create a WebSocket-based command context based on the message var context = new SocketCommandContext(_client, message); // Execute the command with the command context we just // created, along with the service provider for precondition checks. using (var typing = message.Channel.EnterTypingState()) { // Keep in mind that result does not indicate a return value // rather an object stating if the command executed successfully. var result = await _commands.ExecuteAsync( context : context, argPos : argPos, services : null); // Optionally, we may inform the user if the command fails // to be executed; however, this may not always be desired, // as it may clog up the request queue should a user spam a // command. if (!result.IsSuccess) { if (result.Error.Equals(CommandError.BadArgCount) || result.Error.Equals(CommandError.ParseFailed)) { var cmd = message.Content.Replace(Program.prefix.ToString(), "").Split(" ")[0]; await context.Channel.SendMessageAsync("", false, EmbedHelper.GenerateInfoEmbed(BasicCommands.GenerateHelpText(cmd))); } else { await context.Channel.SendMessageAsync("", false, EmbedHelper.GenerateErrorEmbed(result.ErrorReason), allowedMentions : new Discord.AllowedMentions(null), messageReference : new Discord.MessageReference(context.Message.Id)); } } } }