Skip to content

Commit

Permalink
add commands for setting youtube updates channel
Browse files Browse the repository at this point in the history
  • Loading branch information
travv0 committed Apr 3, 2024
1 parent 54a33a5 commit 58db09f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
29 changes: 29 additions & 0 deletions Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -546,3 +550,28 @@ type Commands() =
else
ctx.RespondChunked(channels)
}

[<Command("ytchannel"); Description("Set Discord channel to post YouTube updates to.")>]
member _.YoutubeChannelAsync
(
ctx: CommandContext,
[<Description("The channel to post YouTube updates to.")>] channel: DiscordChannel
) : Task =
task {
do! ctx.TriggerTypingAsync()
updateDb { db with YoutubeChannel = Some channel.Id }
ctx.RespondChunked($"Set YouTube updates channel to **#%s{channel.Name}**")
}

[<Command("ytchannel"); Description("Get the Discord channel that YouTube updates are posted to.")>]
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}**")
}
3 changes: 0 additions & 3 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Db =
AutoReplies: Map<uint64, string>
AutoReplyRates: Map<uint64, decimal>
LastResponse: string option
YoutubeChannel: string option
YoutubeChannel: uint64 option
YoutubeChannels: Set<string>
LastYoutubeFetch: Map<string, DateTime> }

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 58db09f

Please sign in to comment.