コード例 #1
0
        public async Task JoinTwitch()
        {
            SharedBotInfo shared = SharedBotInfo.GetSharedInfo(Context.Guild.Id);

            if (!string.IsNullOrWhiteSpace(shared.TwitchChannelName))
            {
                TwitchChannel chan = Program.TwitchBot.GetChannel(shared.TwitchChannelName);
                if (chan != null)
                {
                    await chan.SendChatMessage("Boo!");

                    await Context.Channel.SendMessageAsync("No need for me to rejoin, I'm already there! Can you see me over in Twitch-land?");
                }
                else
                {
                    await Program.TwitchBot.JoinChannel(shared.TwitchChannelName);

                    await Task.Delay(1000);

                    if (Program.TwitchBot.GetChannel(shared.TwitchChannelName) != null)
                    {
                        await Context.Channel.SendMessageAsync("Figure that, I was able to join your Twitch channel this time! Can you see me over in Twitch-land?");
                    }
                    else
                    {
                        await Context.Channel.SendMessageAsync("I wasn't able to connect to the Twitch channel you linked to this server!");
                    }
                }
            }
            else
            {
                await Context.Channel.SendMessageAsync($"You haven't told me what Twitch channel this server is associated with yet, dummy! *(pssst! use `{Program.Config.CommandPrefix}settwitch`!)*");
            }
        }
コード例 #2
0
        public async Task SetTwitch([Summary("The name of the Twitch channel to link.")] string twitchChannelName)
        {
            SharedBotInfo shared = SharedBotInfo.GetSharedInfo(Context.Guild.Id);

            if (await shared.SetTwitch(twitchChannelName))
            {
                await Program.TwitchBot.JoinChannel(twitchChannelName);

                await Task.Delay(1000);

                if (Program.TwitchBot.GetChannel(twitchChannelName) != null)
                {
                    await Context.Channel.SendMessageAsync("I've found your channel and sent you a friendly little hello message! Can you see me over in Twitch-land?");
                }
                else
                {
                    await Context.Channel.SendMessageAsync("I've set myself a reminder to associate this server with that Twitch channel, but as of now, I was unable to connect to it!");
                }
                shared.SaveSharedInfo();
            }
            else
            {
                await Context.Channel.SendMessageAsync("Another discord server has already been linked to that Twitch channel!");
            }
        }
コード例 #3
0
ファイル: DiscordBot.cs プロジェクト: Jaika1/MizuiroBot
        private async Task MessageReceived(SocketMessage msg)
        {
            SocketUserMessage umsg = (SocketUserMessage)msg;

            if (msg == null)
            {
                return;
            }

            int argPos = 0;

            if (!umsg.HasCharPrefix(CommandPrefix, ref argPos))
            {
                return;
            }
            if (umsg.Author.IsBot)
            {
                return;
            }
            if (umsg.Author.IsWebhook)
            {
                return;
            }
            if (umsg.Channel is SocketDMChannel)
            {
                return;
            }

            var context = new SocketCommandContext(botUser, umsg);

            IResult commandResult = await commandService.ExecuteAsync(context, argPos, null);

            if (commandResult.Error.HasValue)
            {
                if (commandResult.Error.Value != CommandError.UnknownCommand)
                {
                    CVTS.WriteLineError(commandResult.ErrorReason);
                }
                else
                {
                    SharedBotInfo shared = SharedBotInfo.GetSharedInfo(context.Guild.Id);
                    if (shared != null)
                    {
                        try
                        {
                            CustomTwitchCommandInfo customCommand = shared.CustomCommands.First(x => x.Key.StartsWith(umsg.Content.Remove(0, 1)));
                            await context.Channel.SendMessageAsync(customCommand.Value);
                        }
                        catch { }
                    }
                }
            }
        }
コード例 #4
0
        public async Task PartTwitch()
        {
            SharedBotInfo shared = SharedBotInfo.GetSharedInfo(Context.Guild.Id);

            if (!string.IsNullOrWhiteSpace(shared.TwitchChannelName))
            {
                string tChanName = shared.TwitchChannelName;
                shared.RemoveTwitch();
                await Context.Channel.SendMessageAsync($"Pooft! This server is no longer associated with `{tChanName}`!");
            }
            else
            {
                await Context.Channel.SendMessageAsync($"Whoopsie! This server isn't even associated with a Twitch channel in the first place!");
            }
        }
コード例 #5
0
ファイル: SharedModule.cs プロジェクト: Jaika1/MizuiroBot
        public async Task DelSharedCommand([Summary("The command to be removed.")] string command)
        {
            SharedBotInfo shared = SharedBotInfo.GetSharedInfo(Context.Guild.Id);

            if (shared.CustomCommands.Exists(x => x.Key == command))
            {
                CustomTwitchCommandInfo customCommand = shared.CustomCommands.Find(x => x.Key == command);
                shared.CustomCommands.Remove(customCommand);
                await Context.Channel.SendMessageAsync($"Bye bye, `{Program.Config.CommandPrefix}{command}`.");
            }
            else
            {
                await Context.Channel.SendMessageAsync($"I couldn't find that command anywhere!");
            }
            shared.SaveSharedInfo();
        }
コード例 #6
0
 static void Main(string[] args)
 {
     // Enables Console Virtual Terminal Sequences
     CVTS.TryEnable();
     CVTS.WriteLineInfo($"{Process.GetCurrentProcess().ProcessName} version {Process.GetCurrentProcess().MainModule.FileVersionInfo.ProductVersion}, created by Jaika★.");
     // Download/reload Splatoon 2 data from the internet/local storage
     Data.LoadSplatoon2Data();
     // Load the config and shared info.
     Config = Config.LoadConfig();
     SharedBotInfo.LoadSharedInfo();
     SharedUserInfo.LoadUserInfo();
     // Initialise both bots
     DiscordBot.Init();
     TwitchBot.ChannelJoined += TwitchBot_ChannelJoined;
     TwitchBot.Connected     += TwitchBot_Connected;
     // Start both bots
     _ = DiscordBot.StartBot(Config.DiscordBotToken); // Needs discard token '_' since this function is asyncronous.
     _ = TwitchBot.Connect(Config.TwitchBotUsername, Config.TwitchOAuth2);
     // Sleep the thread indefinitely to stop it from closing.
     Thread.Sleep(-1);
 }
コード例 #7
0
ファイル: SharedModule.cs プロジェクト: Jaika1/MizuiroBot
        public async Task SetSharedCommand([Summary("The command to be entered.")] string command, [Remainder][Summary("The response string for said command.")] string response)
        {
            SharedBotInfo shared = SharedBotInfo.GetSharedInfo(Context.Guild.Id);

            if (shared.CustomCommands.Exists(x => x.Key == command))
            {
                CustomTwitchCommandInfo customCommand = shared.CustomCommands.Find(x => x.Key == command);
                customCommand.Value = response;
                await Context.Channel.SendMessageAsync($"The repsonse given for the command `{Program.Config.CommandPrefix}{command}` has been updated successfully!");
            }
            else
            {
                CustomTwitchCommandInfo customCommand = new CustomTwitchCommandInfo()
                {
                    Key   = command,
                    Value = response
                };
                shared.CustomCommands.Add(customCommand);
                await Context.Channel.SendMessageAsync($"Booyah! Your shiny new `{Program.Config.CommandPrefix}{command}` command is ready!");
            }
            shared.SaveSharedInfo();
        }
コード例 #8
0
 private static async Task TwitchBot_ChannelJoined(object sender, ChannelJoinedEventArgs e)
 {
     //await e.Channel.SendChatMessage("I'm alive, yippe!");
     SharedBotInfo.GetSharedInfo(e.Channel.Channel)?.LinkCustomCommands(e.Channel);
 }