From 0bb039b52f07f542ff1de87d37e2972738697e75 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Sat, 7 Feb 2015 14:23:47 -0800 Subject: [PATCH] https://github.com/matthieugrieger/mumbledj/issues/33: Add !setcomment --- CHANGELOG.md | 1 + README.md | 1 + commands.go | 13 +++++++++++++ mumbledj.gcfg | 8 ++++++++ parseconfig.go | 2 ++ strings.go | 4 ++++ 6 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3ec5fa..768ba53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ MumbleDJ Changelog * Removed `sanitize` dependency. * Reworked `Makefile` slightly. * Now uses `gumbleutil.PlainText` for removing HTML tags instead of `sanitize`. +* Added `!setcomment` which allows admin users to set the comment for the bot. ### February 3, 2015 -- `v2.4.1` * Made it possible to place MumbleDJ binary in `~/bin` instead of `/usr/local/bin` if the folder exists. diff --git a/README.md b/README.md index ba6220f..fd761fc 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Command | Description | Arguments | Admin | Example **numsongs** | Outputs the number of songs in the queue in chat. Individual songs and songs within playlists are both counted. | None | No | `!numsongs` **nextsong** | Outputs the title and name of the submitter of the next song in the queue if it exists. | None | No | `!nextsong` **currentsong** | Outputs the title and name of the submitter of the song currently playing. | None | No | `!currentsong` +**setcomment** | Sets the comment for the bot. If no argument is given, the current comment will be removed. | None OR new_comment | Yes | `!setcomment Hello! I am a bot. Type !help for the available commands.` **kill** | Safely cleans the bot environment and disconnects from the server. Please use this command to stop the bot instead of force closing, as the kill command deletes any remaining songs in the `~/.mumbledj/songs` directory. | None | Yes | `!kill` diff --git a/commands.go b/commands.go index 690707a..abf066d 100644 --- a/commands.go +++ b/commands.go @@ -123,6 +123,13 @@ func parseCommand(user *gumble.User, username, command string) { } else { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } + // Setcomment command + case dj.conf.Aliases.SetCommentAlias: + if dj.HasPermission(username, dj.conf.Permissions.AdminSetComment) { + setComment(user, argument) + } else { + dj.SendPrivateMessage(user, NO_PERMISSION_MSG) + } // Kill command case dj.conf.Aliases.KillAlias: if dj.HasPermission(username, dj.conf.Permissions.AdminKill) { @@ -360,6 +367,12 @@ func currentSong(user *gumble.User) { } } +// Performs setcomment functionality. Sets the bot's comment to whatever text is supplied in the argument. +func setComment(user *gumble.User, comment string) { + dj.client.Self().SetComment(comment) + dj.SendPrivateMessage(user, COMMENT_UPDATED_MSG) +} + // Performs kill functionality. First cleans the ~/.mumbledj/songs directory to get rid of any // excess m4a files. The bot then safely disconnects from the server. func kill() { diff --git a/mumbledj.gcfg b/mumbledj.gcfg index 2ec6e96..343e9ba 100644 --- a/mumbledj.gcfg +++ b/mumbledj.gcfg @@ -83,6 +83,10 @@ NextSongAlias = "nextsong" # DEFAULT VALUE: "currentsong" CurrentSongAlias = "currentsong" +# Alias used for the setcomment command +# DEFAULT VALUE: "setcomment" +SetCommentAlias = "setcomment" + # Alias used for kill command # DEFAULT VALUE: "kill" KillAlias = "kill" @@ -147,6 +151,10 @@ AdminNextSong = false # DEFAULT VALUE: false AdminCurrentSong = false +# Make setcomment an admin command? +# DEFAULT VALUE: true +AdminSetComment = true + # Make kill an admin command? # DEFAULT VALUE: true (I recommend never changing this to false) AdminKill = true diff --git a/parseconfig.go b/parseconfig.go index b9a0976..e0227df 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -39,6 +39,7 @@ type DjConfig struct { NumSongsAlias string NextSongAlias string CurrentSongAlias string + SetCommentAlias string KillAlias string } Permissions struct { @@ -55,6 +56,7 @@ type DjConfig struct { AdminNumSongs bool AdminNextSong bool AdminCurrentSong bool + AdminSetComment bool AdminKill bool } } diff --git a/strings.go b/strings.go index 323d15a..775df58 100644 --- a/strings.go +++ b/strings.go @@ -53,6 +53,9 @@ const AUDIO_FAIL_MSG = "The audio download for this video failed. YouTube has li // Message shown to users when they supply a YouTube URL that does not contain a valid ID. const INVALID_YOUTUBE_ID_MSG = "The YouTube URL you supplied did not contain a valid YouTube ID." +// Message shown to user when they successfully update the bot's comment. +const COMMENT_UPDATED_MSG = "The comment for the bot has successfully been updated." + // Message shown to a channel when a new song starts playing. const NOW_PLAYING_HTML = ` @@ -106,6 +109,7 @@ const HELP_HTML = `

!forceskipplaylist - An admin command that forces a playlist skip.

!move - Moves MumbleDJ into channel if it exists.

!reload - Reloads mumbledj.gcfg configuration settings.

+

!setcomment - Sets the comment for the bot.

!kill - Safely cleans the bot environment and disconnects from the server.

`