diff --git a/Commands.fs b/Commands.fs index 9f9b99d..96a0bf2 100644 --- a/Commands.fs +++ b/Commands.fs @@ -503,6 +503,10 @@ type Commands() = ) : Task = task { do! ctx.TriggerTypingAsync() + + if Option.isNone db.YoutubeChannel && ctx.Guild.SystemChannel <> null then + updateDb { db with YoutubeChannel = Some ctx.Guild.SystemChannel.Id } + match! Youtube.getYoutubeChannelId channel with | None -> ctx.RespondChunked($"Could not find a YouTube channel **%s{channel}**") | Some channelId -> @@ -546,3 +550,28 @@ type Commands() = else ctx.RespondChunked(channels) } + + [] + member _.YoutubeChannelAsync + ( + ctx: CommandContext, + [] channel: DiscordChannel + ) : Task = + task { + do! ctx.TriggerTypingAsync() + updateDb { db with YoutubeChannel = Some channel.Id } + ctx.RespondChunked($"Set YouTube updates channel to **#%s{channel.Name}**") + } + + [] + member _.YoutubeChannelAsync(ctx: CommandContext) : Task = + task { + do! ctx.TriggerTypingAsync() + match db.YoutubeChannel with + | None -> ctx.RespondChunked("No YouTube updates channel set") + | Some channelId -> + let channel = ctx.Guild.GetChannel channelId + match channel with + | null -> ctx.RespondChunked("YouTube updates channel no longer exists") + | _ -> ctx.RespondChunked($"YouTube updates channel is **#%s{channel.Name}**") + } diff --git a/Program.fs b/Program.fs index 07d8803..b19b603 100644 --- a/Program.fs +++ b/Program.fs @@ -63,9 +63,6 @@ module Core = Task.CompletedTask let messageCreated (dis: DiscordClient) (e: MessageCreateEventArgs) = - if Option.isNone db.YoutubeChannel then - updateDb { db with YoutubeChannel = Some(e.Guild.SystemChannel.Id.ToString()) } - if not e.Author.IsBot && (Seq.contains dis.CurrentUser e.MentionedUsers || e.Message.Content.Contains("@everyone") diff --git a/Types.fs b/Types.fs index 600828e..b8ad9bd 100644 --- a/Types.fs +++ b/Types.fs @@ -11,7 +11,7 @@ type Db = AutoReplies: Map AutoReplyRates: Map LastResponse: string option - YoutubeChannel: string option + YoutubeChannel: uint64 option YoutubeChannels: Set LastYoutubeFetch: Map } @@ -43,6 +43,7 @@ type Db = YoutubeChannel = Decode.string |> get.Optional.Field "YoutubeChannel" + |> Option.map uint64 YoutubeChannels = Decode.list Decode.string |> get.Optional.Field "YoutubeChannels"