Skip to content

command.go: modifying Theme command to show all available themes#232

Merged
shazow merged 1 commit intoshazow:masterfrom
ste5e99:theme-stuff
May 7, 2017
Merged

command.go: modifying Theme command to show all available themes#232
shazow merged 1 commit intoshazow:masterfrom
ste5e99:theme-stuff

Conversation

@ste5e99
Copy link
Copy Markdown
Contributor

@ste5e99 ste5e99 commented May 5, 2017

Shows all themes on an empty /theme call. Not a very friendly way to join all the strings since all the Theme names are locked behind theme.ID(). It's either do each ID call in each cycle of the loop and add it to a string, or build a list of all the Theme names, then use String.Join to merge them all together and use that. (Third option: have a list of all theme strings somewhere to avoid having to do iteration/list building every time someone calls /theme?)

chat/command.go Outdated
theme = cfg.Theme.ID()
}
body := fmt.Sprintf("Current theme: %s", theme)
avail := "Themes available: "
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO append to a buffer.

var avail bytes.Buffer
fmt.Fprintf(&avail, "Themes available: ")
...
room.Send(message.NewSystemMsg(avail.String(), user))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I amended it but had to add the bytes import as well for bytes.Buffer.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is tradition.

@shazow
Copy link
Copy Markdown
Owner

shazow commented May 6, 2017

LGTM. Wanna figure out why travis is upset?

@ste5e99
Copy link
Copy Markdown
Contributor Author

ste5e99 commented May 6, 2017

I filed an issue for that in #231.

Edit: im dumb

@shazow
Copy link
Copy Markdown
Owner

shazow commented May 6, 2017

It's not the same error as #231. This looks like a linting thing.

@ste5e99
Copy link
Copy Markdown
Contributor Author

ste5e99 commented May 7, 2017

The linter says Line 125 on host.go, but I think the problem carried over from the batch of commits you added on the refactor branch. Here's the diff from doing git diff master..theme-stuff -- host.go

-       if h.isOp(term.Conn) {
-               h.Room.Ops.Add(set.Itemize(member.ID(), member))
+       if key := term.Conn.PublicKey(); key != nil {
+               authItem, err := h.auth.ops.Get(newAuthKey(key))
+               if err == nil {
+                       err = h.Room.Ops.Add(set.Rename(authItem, member.ID()))
+               }
+       }
+       if err != nil {
+               logger.Warningf("[%s] Failed to op: %s", term.Conn.RemoteAddr(), err)
        }
-       ratelimit := rateio.NewSimpleLimiter(3, time.Second*3)

+       ratelimit := rateio.NewSimpleLimiter(3, time.Second*3)
        logger.Debugf("[%s] Joined: %s", term.Conn.RemoteAddr(), user.Name())

It claims that err = h.Room.Ops.Add(set.Rename(authItem, member.ID())) is an ineffective assign. But I'm not entirely certain as to why.

Edit: changing target branch to master as per previous discussion to develop features from master.

@ste5e99 ste5e99 changed the base branch from refactor to master May 7, 2017 15:17
chat/command.go Outdated
@@ -191,6 +192,15 @@ func InitCommands(c *Commands) {
theme = cfg.Theme.ID()
}
body := fmt.Sprintf("Current theme: %s", theme)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanna put the body into the buffer too, while we're at it? lolol

@ste5e99
Copy link
Copy Markdown
Contributor Author

ste5e99 commented May 7, 2017

Updated to use a single byte buffer instead of sending two separate messages. I used three spaces to keep it properly indented with the system message arrow. I didn't do the inner check skip just because I thought it would further complicate it a bit.

body := fmt.Sprintf("Current theme: %s", theme)
room.Send(message.NewSystemMsg(body, user))
var output bytes.Buffer
fmt.Fprintf(&output, "Current theme: %s%s", theme, message.Newline)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit but IMO:

- fmt.Fprintf(&output, "Current theme: %s%s", theme, message.Newline)
+ fmt.Fprintf(&output, "Current theme: %s" + message.Newline, theme)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whichever one you prefer I'll go with. I thought using the direct formatting would look better than doing string addition but it's up to you.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's kinda the equivalent of writing ("Current theme: %s%s", foo, "\n") which feels weird to me vs ("Current theme: %s\n", foo).

I'll merge it either way, just let me know when it's ready for merging. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ready. I got nothing else to add.

@shazow shazow changed the title (WIP) command.go: modifying Theme command to show all available themes command.go: modifying Theme command to show all available themes May 7, 2017
@shazow shazow merged commit 227dad7 into shazow:master May 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants