r/csharp • • Dec 01 '13

Kiwana - A C# IRC Bot

Hi there, fellow C# fans. Please take a look at the IRC Bot I'm working on. I'd like to have some constructive criticism on the code and/or suggestions what to add.

Here's the repository: http://github.com/Banane9/Kiwana

I will update it on github and answer to the people suggesting changes here to take a look at them.

17 Upvotes

28 comments sorted by

4

u/[deleted] Dec 01 '13

I only had a cursory glance, but I'd say two things:

One: Maybe you should encapsulate a few more things as objects rather than strings - i.e. a 'user' object and such. But that's up to you.

Two: Users = users != null ? users : new List<string>(); can be Users = users ?? new List<string>();

1

u/Banane9 Dec 02 '13

Thanks for the new operator :D

The users in the channels are saved as strings because I don't need any information about them. The users the Bot knows more about are saved in the Users dictionary with a string key and user-object. I don't know what other strings you could mean, right now.

4

u/gsuberland Dec 01 '13

More people should learn about the null coalescing operator. It's awesome.

→ More replies (2)

2

u/GeorgeHahn Dec 01 '13

Mind if I spend some time tidying with you? I've been trying to do a weekly-bimonthly PR to a random FOSS C# project and this looks pretty appealing.

1

u/Banane9 Dec 02 '13

Sounds good, just fork it on github :) PM me for Skype info or on IRC I'm on esper.net as Banane9

2

u/Uncled1023 Dec 01 '13

Looking at it you have a good start. Pretty similar to what I am also doing. One thing I can point out is that to make sure you account for all issues with the server. Server timeout, *.net split, Nick taken, Nick needs identifying, possible ghosting of used nick, nick registration, differences between server messages from server to server.

Also, i would move your hard-coded commands within the main project to a plugin, since that is where all the other commands are located.

I don't want to distract from your thread, so msg me if you want to take a look at what i've done for some ideas.

1

u/Banane9 Dec 02 '13

The commands in there are all that modify the state of the Bot (join, part, nick, quit) or that require information the plugins don't have at this point (help, plugins, about)

I agree that I need to add more server stuff. I pretty much only focused on esper.net because I tested it there and I was able to identify with nickserv by writing pass in the stream when initially connecting. I didn't see what the *.net split looks like as a message yet. Do you know how it looks or where those are specified?

→ More replies (5)

8

u/Seikho_M Dec 01 '13

Consider refactoring your methods and taking a more object-orientated approach.

By refactoring, I mean shrink them. Make them more descriptive and easier to read and maintain. For example, in your 'Kiwana' project, the ParseLine() function is enormous. It could be reduced to 4 or 5 lines of code.

The goal is your code is readable by anyone. Your comments should never describe what you are doing, only why you are doing something. If you need a comment to describe what, you need to amend your code.

There is plenty of opportunity in your project to implement common design patterns (http://www.dofactory.com/Patterns/Patterns.aspx) and simple classes.

Overall, you seem to have the functionality down. It just needs tidying, which is a skill that comes with a lot of time and patience. You'll appreciate coming back to your code 5 years later and being able to read it without scratching your head.

3

u/gsuberland Dec 01 '13

I'd also comment that the plugin abstract class should be an interface.

→ More replies (6)
→ More replies (1)

1

u/rockyearth Dec 01 '13
using System.Linq;
using System.Text;

Useless includes.

Many magic numbers , not easy to see what the code does.

→ More replies (3)