Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit #1

Merged
merged 6 commits into from
Dec 23, 2020
Merged

Initial commit #1

merged 6 commits into from
Dec 23, 2020

Conversation

matanp
Copy link
Owner

@matanp matanp commented Dec 7, 2020

This is the initial commit.

Twitch_main.js is the entry point and uses the main method from bot_brain.js

twitch main sets up twitch client and handles messages coming in - sometimes sending message back out.

https://dev.twitch.tv/docs/irc has documentation on setting up twitch client.

@matanp
Copy link
Owner Author

matanp commented Dec 7, 2020

quick note that the dependencies listed in package.json are not used in anything in the initial commit, just dependences for beta functionality.

@unfamiliarish2 unfamiliarish2 self-requested a review December 22, 2020 05:00
Copy link
Collaborator

@unfamiliarish2 unfamiliarish2 left a comment

Choose a reason for hiding this comment

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

Great work! This is a fun project, and I'm stoked to see where you go with it! 🤹

Most of my comments have to do with formatting, organization, or naming/style conventions.

Let me know if you want me to look back over it after you make your updates, or if you'd prefer just a first pass from me 🌻

.gitignore Outdated
@@ -0,0 +1,3 @@
node_modules/
.env
log/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider sorting these alphabetically and also by type. Maybe:

log/
node_modules/
.env

twitch_main.js Outdated
Comment on lines 33 to 38
// Called every time a message comes in
// target is the twitch channel the message is coming from
// context is information about the user -- see example_context
// msg is the actual message
// self is a boolean of if the message is coming from this client
function onMessageHandler (target, context, msg, self) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here's the Google style guide for js:
https://google.github.io/styleguide/jsguide.html

I'm linking it cause I used the python one a lot for standards on writing docstring when I first started at Freenome.

I am totally bikeshedding, but some things here you could tweak:

  • Multi-line comments in js are /* */, and
  • I've hyperlinked here how google recommends formatting js docstring

Optionally also consider using typescript for typing. Probably not worth for now since the project is young, but would be worth checking out if it grows.

Copy link
Owner Author

Choose a reason for hiding this comment

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

thank you for bikeshedding, especially since I'm so new to javascript. definitely thinking about switching over to typescript

twitch_main.js Outdated
Comment on lines 33 to 38
// Called every time a message comes in
// target is the twitch channel the message is coming from
// context is information about the user -- see example_context
// msg is the actual message
// self is a boolean of if the message is coming from this client
function onMessageHandler (target, context, msg, self) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's also this idea of "self-documenting code", which if you haven't heard of it before gets at the idea of structuring your code and naming your variables, functions, etc, in such a way that you can minimize inclusion of comments. Grabbed the first link that seemed okay

Again, small project, but the idea is that over time, because they're not required to be accurate (like the actual code), comments commonly fall out of date. As a result, it's a good idea to minimize use of comments as much as possible.

An alternative to your current function signature could be:

function onMessageHandler (sending_twitch_channel, user_info, user_msg, msg_from_self) {

Copy link
Owner Author

Choose a reason for hiding this comment

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

great idea to be more self documenting, I like these names better (went with something slightly different, but similar)

twitch_main.js Outdated
Comment on lines 6 to 10
//twitch client
const tmi = require('tmi.js');

//and we need the bot
const { bot } = require('./bot_brain.js');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lol so I know these come from this tutorial, but I'd rename these:

  • tmi -> twitch_client
  • opts -> options

Since I think this is easier to understand ⭐

Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoops, grabbed the wrong line for opts

Comment on lines +46 to +48
}

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Inconsistent indentation. These are 4 spaces, but earlier you have 2

bot_brain.js Outdated
Comment on lines 21 to 26
if (r_num > 9) {
msg_out = "matanbot is currently under development, please excuse the lack of functionality"
} else if (r_num > 8){
msg_out = "I'm so glad someone recognizes my potential as being the best bot on the channel"
} else if (r_num > 6) {
msg_out = "I am a juggle bot, that is all I am"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice easter eggs! 😛

bot_brain.js Outdated
Comment on lines 13 to 14
var r_num = Math.floor((Math.random() * 10) + 1);
var msg_out = "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should be consts

Copy link
Owner Author

Choose a reason for hiding this comment

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

msg_out can't be a const because I am changing it in the function body - is there a cleaner way to do this so I'm not modifying the value of the variable?

function message_main (context, msg) {
// Remove whitespace from chat message
const commandName = msg.trim();

Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally, I would take out this extra line, but that's just my style.

More bikeshedding that is up to you and/or whatever linter you maybe pick up

bot_brain.js Outdated
const upper_case = commandName.toUpperCase();

//random number 1 to 10
var r_num = Math.floor((Math.random() * 10) + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would also rename r_num to a more obvious name (like random_num), but up to you
https://dzone.com/articles/naming-conventions-from-uncle-bobs-clean-code-phil

Copy link
Owner Author

Choose a reason for hiding this comment

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

good idea!

bot_brain.js Outdated
Comment on lines 20 to 24
count = count + 1;
if (r_num > 9) {
msg_out = "matanbot is currently under development, please excuse the lack of functionality"
} else if (r_num > 8){
msg_out = "I'm so glad someone recognizes my potential as being the best bot on the channel"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optionally break these if statement bodies into their own functions, which would remove the extra layers of nesting here.

Probably put the r_num statement into this if body, unless it is intended to be used elsewhere.
Consider also renaming count to a more descriptive name.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you do break them out, I have been working on keeping to a pretty functional programming style, which I would also recommend.

It allows for super deterministic plug-n-play methods, which also minimizing coupling of your code (cough workday cough), allowing for easier future modifications/expansion to your code

Copy link
Owner Author

Choose a reason for hiding this comment

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

not going to do this for this push - but definitely considering it going forward! would love to chat about how best to structure the functions, and what exactly they should take in and pass out. Ideally, I'd like some re-usable function to read some json file or something with all the commands, so I can add functionality w/o really adding code. Not sure entirely how I wanna do that yet though.

@matanp
Copy link
Owner Author

matanp commented Dec 23, 2020

going to close and merge the PR here, don't wanna get too caught up on style right now. I have a bunch of beta code that would be a better use of time to be working on.

thank you for reviewing! much appreciated

@matanp matanp merged commit 1b72449 into main Dec 23, 2020
@matanp matanp deleted the initial_commit branch December 30, 2020 10:52
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