コード例 #1
0
        public async Task RegisterChannel(CommandContext ctx, DiscordChannel channel = null)
        {
            // get member's voice state
            var vstat = ctx.Member?.VoiceState;

            if (vstat?.Channel == null)
            {
                // they did not specify a channel and are not in one
                await ctx.RespondAsync("You are not in a voice channel.");

                return;
            }

            GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, vstat.Channel.Guild, true);

            if (handler != null)
            {
                handler.AddChannel(vstat.Channel); //Could throw access violation because we run the handlers async, this needs fixing
            }
            if (!handler.IsRunning)
            {
                handler.Execute(); //Will run async
            }
            await ctx.RespondAsync($"Registered to `{vstat.Channel.Name}`");
        }
コード例 #2
0
        public async Task UnregisterChannel(CommandContext ctx, DiscordChannel channel = null)
        {
            // get member's voice state
            var vstat = ctx.Member?.VoiceState;

            if (vstat?.Channel == null)
            {
                // they did not specify a channel and are not in one
                await ctx.RespondAsync("You are not in a voice channel.");

                return;
            }

            GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, vstat.Channel.Guild, false);

            if (handler != null)
            {
                handler.RemoveChannel(vstat.Channel); //Could throw access violation because we run the handlers async, this needs fixing
                await ctx.RespondAsync($"Unregistered `{vstat.Channel.Name}`");

                return;
            }

            await ctx.RespondAsync("No channels registered yet.");
        }
コード例 #3
0
        public async Task ClearData(CommandContext ctx)
        {
            GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, ctx.Guild, true);

            handler.ClearGuildData();
            await ctx.RespondAsync($"Cleared all data for this guild");
        }
コード例 #4
0
        public async Task Announce(CommandContext ctx, [RemainingText, Description("path to the file to play.")] string filename)
        {
            GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, ctx.Guild, true);

            if (handler != null)
            {
                await ctx.RespondAsync($"Will announce `{filename}`");

                await handler.AnnounceFile(filename);

                await ctx.RespondAsync($"Done announcing `{filename}`");
            }
        }
コード例 #5
0
        //Hooked up in program.cs
        public static void StartupGuildHandler(DiscordClient sender, GuildCreateEventArgs e)
        {
            // let's log the name of the guild that was just
            // sent to our client
            //sender.Logger.LogInformation(Program.BotEventId, $"Guild available: {e.Guild.Name}");

            //Create or get the handler for this guild
            GuildHandler handler = KoekoeController.GetGuildHandler(sender, e.Guild);

            //Read our saved data
            string guilddata_path = Path.Combine(Environment.CurrentDirectory, "data", $"guilddata_{e.Guild.Id}.json");

            if (File.Exists(guilddata_path))
            {
                string json    = File.ReadAllText(guilddata_path).ToString();
                var    dataObj = JsonConvert.DeserializeObject <SavedGuildData>(json);
                //Restore registered channels
                if (dataObj.channelIds != null)
                {
                    foreach (ulong channelid in dataObj.channelIds)
                    {
                        DiscordChannel channel = e.Guild.GetChannel(channelid);

                        if (channel != null)
                        {
                            handler.AddChannel(channel, false);
                        }
                    }
                }

                //Restore alarms
                if (dataObj.alarms != null)
                {
                    foreach (AlarmData alarm in dataObj.alarms)
                    {
                        if (alarm != null)
                        {
                            handler.AddAlarm(alarm.AlarmDate, alarm.AlarmName, alarm.userId, false);
                        }
                    }
                }
            }

            if (!handler.IsRunning) //Run the handler loop if it's not already started
            {
                handler.Execute();
            }
        }
コード例 #6
0
        public async Task ListRegister(CommandContext ctx, DiscordChannel channel = null)
        {
            GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, ctx.Channel.Guild, false);

            if (handler != null)
            {
                string channelstext = String.Join("`, `", handler.GetRegisteredChannelNames());

                await ctx.RespondAsync($"Currently registered to: `{channelstext}`");

                return;
            }


            await ctx.RespondAsync($"Currently not registered to any channel, use `!kk register` while in a voice channel to add it.");
        }
コード例 #7
0
        public async Task SetAlarm(CommandContext ctx, string alarmname, [RemainingText, Description("Alarm time ex 4:20 or 15:34")] string datestring)
        {
            // get member's voice state
            var vstat = ctx.Member?.VoiceState;

            if (vstat?.Channel == null)
            {
                // they did not specify a channel and are not in one
                await ctx.RespondAsync("You are not in a voice channel.");

                return;
            }

            string[] datestringComps = datestring.Split(':');
            if (datestringComps.Length == 2)
            {
                int parsedHours, parsedMinutes;
                if (int.TryParse(datestringComps[0], out parsedHours) && int.TryParse(datestringComps[1], out parsedMinutes))
                {
                    if (parsedHours > 0 && parsedHours < 24 && parsedMinutes > 0 && parsedMinutes < 60)
                    {
                        int hourdiff = (parsedHours - DateTime.Now.Hour) % 24;
                        if (hourdiff < 0)
                        {
                            hourdiff += 24;
                        }

                        int      mindiff = (parsedMinutes - DateTime.Now.Minute) % 60;
                        DateTime dt      = DateTime.Now.AddHours(hourdiff).AddMinutes(mindiff).AddSeconds(-DateTime.Now.Second);

                        GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, vstat.Channel.Guild, true);

                        handler.AddAlarm(dt, alarmname, ctx.User.Id);

                        if (!handler.IsRunning) //If the handler isn't running for some reason start it TODO: remove these, or implement handler sleep
                        {
                            handler.Execute();  //Will run async
                        }
                    }
                }
            }

            await ctx.RespondAsync($"Registered alarm `{alarmname}` to `{ctx.User.Username}`");
        }
コード例 #8
0
        public async Task CancelAlarm(CommandContext ctx, string alarmname)
        {
            GuildHandler     handler = KoekoeController.GetGuildHandler(ctx.Client, ctx.Guild);
            List <AlarmData> alarms  = handler.GetAlarms();

            for (int i = 0; i < alarms.Count; i++)
            {
                if (alarms[i].AlarmName == alarmname && alarms[i].userId == ctx.User.Id)
                {
                    alarms.RemoveAt(i);
                    handler.SaveGuildData();
                    await ctx.RespondAsync($"Canceled alarm `{alarmname}`");

                    return;
                }
            }

            await ctx.RespondAsync($"Couldn't find alarm `{alarmname}`");
        }
コード例 #9
0
        public async Task ListAlarm(CommandContext ctx, DiscordChannel channel = null)
        {
            GuildHandler handler = KoekoeController.GetGuildHandler(ctx.Client, ctx.Channel.Guild, false);

            if (handler != null)
            {
                List <AlarmData> alarms     = handler.GetAlarms();
                string[]         alarmtexts = new string[alarms.Count];
                for (int i = 0; i < alarmtexts.Length; i++)
                {
                    DiscordMember member = await ctx.Guild.GetMemberAsync(alarms[i].userId);

                    alarmtexts[i] = $"{member.Username}: {alarms[i].AlarmDate.ToShortTimeString()} ({alarms[i].AlarmName})";
                }
                string alarmstext = String.Join("`\n`", alarmtexts);

                await ctx.RespondAsync($"Currently Alarms:\n{alarmstext}");

                return;
            }


            await ctx.RespondAsync($"Currently not registered to any channel, use `!kk register` while in a voice channel to add it.");
        }