Skip to content

Commit

Permalink
Add a mute function
Browse files Browse the repository at this point in the history
  • Loading branch information
quackduck committed Dec 13, 2023
1 parent c758c19 commit 3623724
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var (
{"lsbans", listBansCMD, "", "List banned IDs"},
{"ban", banCMD, "`user` [`reason`] [`dur`]", "Ban <user> and optionally, with a reason or duration (admin)"},
{"unban", unbanCMD, "IP|ID [dur]", "Unban a person (admin)"},
{"mute", muteCMD, "`user`", "Mute <user> (admin)"},
{"unmute", unmuteCMD, "`user`", "Unmute <user> (admin)"},
{"kick", kickCMD, "`user`", "Kick <user> (admin)"},
{"art", asciiArtCMD, "", "Show some panda art"},
{"pwd", pwdCMD, "", "Show your current room"},
Expand Down Expand Up @@ -100,6 +102,11 @@ func init() {
func runCommands(line string, u *User) {
line = rmBadWords(line)

if u.IsMuted {
u.writeln(u.Name, line)
return
}

if line == "" {
return
}
Expand Down Expand Up @@ -591,6 +598,32 @@ func kickCMD(line string, u *User) {
victim.close(victim.Name + Red.Paint(" has been kicked by ") + u.Name)
}

func muteCMD(line string, u *User) {
victim, ok := findUserByName(u.room, line)
if !ok {
u.room.broadcast("", "User not found")
return
}
if !auth(u) && victim.id != u.id {
u.room.broadcast(Devbot, "Not authorized")
return
}
victim.IsMuted = true
}

func unmuteCMD(line string, u *User) {
victim, ok := findUserByName(u.room, line)
if !ok {
u.room.broadcast("", "User not found")
return
}
if !auth(u) && victim.id != u.id {
u.room.broadcast(Devbot, "Not authorized")
return
}
victim.IsMuted = false
}

func colorCMD(rest string, u *User) {
if rest == "which" {
u.room.broadcast(Devbot, u.Color+" "+u.ColorBG)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type User struct {
Bell bool
PingEverytime bool
isBridge bool
IsMuted bool
FormatTime24 bool

Color string
Expand Down

0 comments on commit 3623724

Please sign in to comment.