raisedragon / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Missing Interface for action, message and notice #236

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
My current implementation reacts to every kind of message event in the same 
way. The problem when using the send() method of a channel or user is, that the 
resulting OutputChannel or OutputUser are not exchangeable.

Let me give you an example:

if(event instanceof MessageEvent) {
    OutputChannel out = ((MessageEvent) event).getChannel().send();
    out.message("This is a simple message!");
} else {
    OutputUser out = event.getUser().send();
    out.message("This is a simple message!");
}

Depending on the complexity of the task this kind of generic code will lead to 
a lot of code duplication. Wouldn't it be awesome to have an Interface that 
works for both, channels and users? This would remove the code duplication:

GenericChannelUserOutput out = null;
if(event instanceof MessageEvent) {
    out = ((MessageEvent) event).getChannel().send();
} else {
    out = event.getUser().send();
}
out.message("This is a simple message!");

I know there is an event.respond() method but I don't like it. You are not 
flexible. It cannot send actions and notices and always prepends the Nickname 
if it is a ChannelEvent.

I will provide a Pull Request on Github for this.

Original issue reported on code.google.com by lo...@amshaegar.de on 3 Mar 2015 at 12:42

GoogleCodeExporter commented 9 years ago
https://github.com/TheLQ/PircBotX/pull/1

Original comment by lo...@amshaegar.de on 3 Mar 2015 at 1:53

GoogleCodeExporter commented 9 years ago
What's wrong with event.respond() ? MessageEvent will respond to the channel, 
PrivateMessageEvent will respond to the user. 

I'll merge this soon

Original comment by Lord.Qua...@gmail.com on 4 Mar 2015 at 4:02

GoogleCodeExporter commented 9 years ago
As I said. You cannot respond with an action or notice and i don't like that 
the user's name is prepended. You may want to execute a command and bot need's 
to address several users in the channel. So it would look like this:

AmShaegar > !play
Bot > AmShaegar: User1: You are the knight.
Bot > AmShaegar: User2: You are the archer.
Bot > ...

This is just an example but I hope you can understand what's bothering me.

Original comment by lo...@amshaegar.de on 4 Mar 2015 at 7:35

GoogleCodeExporter commented 9 years ago
This was added on Github. Thanks!

Original comment by Lord.Qua...@gmail.com on 4 Apr 2015 at 9:35

GoogleCodeExporter commented 9 years ago

Original comment by Lord.Qua...@gmail.com on 4 Apr 2015 at 9:35