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

Member joined listener #291

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions samples/events/src/main/java/events/MemberJoinedChannel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package events;

import com.ullink.slack.simpleslackapi.SlackChannel;
import com.ullink.slack.simpleslackapi.SlackSession;
import com.ullink.slack.simpleslackapi.SlackUser;
import com.ullink.slack.simpleslackapi.events.*;
import com.ullink.slack.simpleslackapi.impl.SlackSessionFactory;
import com.ullink.slack.simpleslackapi.listeners.SlackChannelJoinedListener;
import com.ullink.slack.simpleslackapi.listeners.SlackChannelLeftListener;
import com.ullink.slack.simpleslackapi.listeners.SlackMemberJoinedListener;
import com.ullink.slack.simpleslackapi.listeners.SlackMessagePostedListener;

import java.io.IOException;

public class MemberJoinedChannel {
public static void main(String[] args) throws IOException {
SlackSession session = SlackSessionFactory.createWebSocketSlackSession(" xoxb..... - add bot auth token here");
session.connect();
SlackChannel channel = session.findChannelByName("general"); //make sure bot is a member of the channel.

//optional item
//send a message to the channel when connection is established
session.sendMessage(channel, "hello world, i'm a bot and I just connected" );

// Define the Member Joined listener
SlackMemberJoinedListener slackMemberJoinedListener = new SlackMemberJoinedListener() {
public void onEvent(SlackMemberJoined event, SlackSession session) {
SlackChannel slackChannel = event.getChannel();
if(event.getChannel()==null)
System.out.println("Error: Getting slack channel as null");

//optional item
//send a message to the channel when a new member joins the channel
session.sendMessage(event.getChannel(),"Welcome to the channel :) !");
System.out.println(event.toString());
}
};

//add it to the session
session.addSlackMemberJoinedListener(slackMemberJoinedListener);
}
}
27 changes: 27 additions & 0 deletions sources/src/main/etc/FindBugs & PMD/FindBugs_PMD_Report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This is a Slack Member_Joined_Channel feature issue, where I had to contribute to multiple existing files and create a couple of new files to implement a new type of Listener.
So, I run the report for this feature's module including all the pre-exsiting files.
I used an Intellij plugin - QAPlug to run Findbugs and PMD report.

Although there are reports shown in the report file here, there are no new errors caused by my contribution.


Please note that my contributions affected only the following files:

1. [SlackMemberJoined.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/events/SlackMemberJoined.java)
2. [SlackMemberJoinedListener.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/listeners/SlackMemberJoinedListener.java)
3. [AbstractSlackSessionImpl.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/impl/AbstractSlackSessionImpl.java)
4. [SlackWebSocketSessionImpl.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/impl/SlackWebSocketSessionImpl.java)
5. [SlackSession.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/SlackSession.java)
6. [SlackSessionWrapper.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/SlackSessionWrapper.java)
7. [SlackEventType.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/events/SlackEventType.java)
8. [EventType.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/events/EventType.java)
9. [SlackJSONMessageParser.java](https://github.com/rajanpatel4578/simple-slack-api/blob/MemberJoinedListener/sources/src/main/java/com/ullink/slack/simpleslackapi/impl/SlackJSONMessageParser.java)

Bug Report After
![image](https://user-images.githubusercontent.com/33018692/142755449-c67b42b4-ff7d-4bc5-beb7-09ae21475ac2.png)




Bug Report Before
![image](https://user-images.githubusercontent.com/33018692/142755413-9ab61508-d726-4ef5-a79f-bbbd224eb3b4.png)
12 changes: 12 additions & 0 deletions sources/src/main/etc/FindBugs & PMD/qaplug_result_After.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>QAPlug scan results</title>
<meta name="description" content="QAPlug scan results"></head>
<body>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="font-family:verdana; font-weight:bold; color:#005555; size = 3">Project:</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>simple-slack-api-master - Copy</b><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="font-family:verdana; font-weight:bold; color:#005555; size = 3">Scope:</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Project 'simple-slack-api-master - Copy'</b><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="font-family:verdana; font-weight:bold; color:#005555; size = 3">Profile:</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Default</b><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="font-family:verdana; font-weight:bold; color:#005555; size = 3">Results:</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Enabled coding rules: 429</b><br/><ul><li>FindBugs: 346</li><li>PMD: 83</li></ul>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Problems found: 57</b><br/><ul><li>FindBugs: 0</li><li>PMD: 57</li></ul><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="font-family:verdana; font-weight:bold; color:#005555; size = 3">Time statistics:</font><ul><li>Started: Sun Nov 21 00:27:29 PST 2021</li><ul><li>Initialization: 00:00:00.015</li><li>PMD: 00:00:05.262</li><li>FindBugs: 00:00:01.436</li><li>Gathering results: 00:00:00.393</li></ul><li>Finished: Sun Nov 21 00:27:36 PST 2021</li></ul>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style="font-family:verdana; font-weight:bold; color:#005555; size = 3">Detailed Results:</font><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>simple-slack-api-master - Copy</b><br/><ul><li>Maintainability</li><ul><li>Avoid Duplicate Literals</li><ul><li>SlackJSONMessageParser</li><ul><li>The String literal "type" appears 4 times in this file; the first occurrence is on line 59 - line: 58</li><li>The String literal "channel" appears 13 times in this file; the first occurrence is on line 107 - line: 106</li><li>The String literal "user" appears 14 times in this file; the first occurrence is on line 109 - line: 108</li><li>The String literal "message" appears 5 times in this file; the first occurrence is on line 212 - line: 211</li><li>The String literal "text" appears 6 times in this file; the first occurrence is on line 213 - line: 212</li><li>The String literal "file" appears 8 times in this file; the first occurrence is on line 291 - line: 290</li><li>The String literal "item" appears 4 times in this file; the first occurrence is on line 334 - line: 333</li><li>The String literal "event_ts" appears 4 times in this file; the first occurrence is on line 343 - line: 342</li></ul><li>SlackJSONParsingUtils</li><ul><li>The String literal "name" appears 4 times in this file; the first occurrence is on line 19 - line: 18</li></ul><li>SlackWebSocketSessionImpl</li><ul><li>The String literal "token" appears 23 times in this file; the first occurrence is on line 556 - line: 555</li><li>The String literal "channel" appears 14 times in this file; the first occurrence is on line 557 - line: 556</li><li>The String literal "text" appears 5 times in this file; the first occurrence is on line 558 - line: 557</li><li>The String literal "true" appears 4 times in this file; the first occurrence is on line 561 - line: 560</li><li>The String literal "false" appears 4 times in this file; the first occurrence is on line 586 - line: 585</li><li>The String literal "user" appears 4 times in this file; the first occurrence is on line 658 - line: 657</li><li>The String literal "presence" appears 4 times in this file; the first occurrence is on line 1,020 - line: 1019</li><li>The String literal "UTF-8" appears 4 times in this file; the first occurrence is on line 1,049 - line: 1048</li><li>The String literal "type" appears 5 times in this file; the first occurrence is on line 1,145 - line: 1144</li></ul></ul><li>Collapsible If Statements</li><ul><li>AbstractSlackSessionImpl</li><ul><li>These nested if statements could be combined - line: 103</li></ul></ul><li>Loose coupling</li><ul><li>SlackJSONMessageParser</li><ul><li>Avoid using implementation types like 'ArrayList'; use the interface instead - line: 461</li></ul><li>SlackMessagePosted</li><ul><li>Avoid using implementation types like 'ArrayList'; use the interface instead - line: 29</li><li>Avoid using implementation types like 'ArrayList'; use the interface instead - line: 99</li><li>Avoid using implementation types like 'ArrayList'; use the interface instead - line: 115</li></ul><li>SlackMessageUpdated</li><ul><li>Avoid using implementation types like 'ArrayList'; use the interface instead - line: 12</li><li>Avoid using implementation types like 'ArrayList'; use the interface instead - line: 47</li><li>Avoid using implementation types like 'ArrayList'; use the interface instead - line: 49</li></ul></ul><li>Unused formal parameter</li><ul><li>SlackJSONMessageParser</li><ul><li>Avoid unused method parameters such as 'slackSession'. - line: 113</li><li>Avoid unused method parameters such as 'slackSession'. - line: 127</li><li>Avoid unused method parameters such as 'slackSession'. - line: 134</li><li>Avoid unused method parameters such as 'slackSession'. - line: 358</li></ul></ul><li>Unused local variable</li><ul><li>FetchingMessageHistory</li><ul><li>Avoid unused local variables such as 'messages'. - line: 24</li><li>Avoid unused local variables such as 'messages'. - line: 35</li><li>Avoid unused local variables such as 'messages'. - line: 46</li><li>Avoid unused local variables such as 'messages'. - line: 57</li></ul><li>ListeningToMessageEvents</li><ul><li>Avoid unused local variables such as 'channelOnWhichMessageWasPosted'. - line: 24</li><li>Avoid unused local variables such as 'messageContent'. - line: 25</li><li>Avoid unused local variables such as 'messageSender'. - line: 26</li></ul><li>RetrieveInformation</li><ul><li>Avoid unused local variables such as 'emojiUrl'. - line: 22</li></ul></ul><li>Unused Private Field</li><ul><li>SlackFile</li><ul><li>Avoid unused private fields such as 'url'. - line: 12</li><li>Avoid unused private fields such as 'urlDownload'. - line: 13</li></ul></ul></ul><li>Reliability</li><ul><li>Avoid Catching Throwable</li><ul><li>SlackWebSocketSessionImpl</li><ul><li>A catch statement should never catch throwable since it includes errors. - line: 286</li></ul></ul></ul><li>Usability</li><ul><li>Avoid Print Stack Trace</li><ul><li>SlackWebSocketSessionImpl</li><ul><li>Avoid printStackTrace(); use a logger call instead. - line: 1055</li><li>Avoid printStackTrace(); use a logger call instead. - line: 1079</li><li>Avoid printStackTrace(); use a logger call instead. - line: 1109</li><li>Avoid printStackTrace(); use a logger call instead. - line: 1153</li><li>Avoid printStackTrace(); use a logger call instead. - line: 1172</li><li>Avoid printStackTrace(); use a logger call instead. - line: 1216</li><li>Avoid printStackTrace(); use a logger call instead. - line: 1236</li></ul></ul><li>Avoid Throwing Null Pointer Exception</li><ul><li>ReaderUtils</li><ul><li>Avoid throwing null pointer exceptions. - line: 27</li></ul></ul><li>If Stmts Must Use Braces</li><ul><li>OverflowMenu</li><ul><li>Avoid using if statements without curly braces - line: 28</li><li>Avoid using if statements without curly braces - line: 29</li></ul><li>SlackJSONMessageParser</li><ul><li>Avoid using if statements without curly braces - line: 462</li></ul></ul><li>Naming - Class naming conventions</li><ul><li>ChannelHistoryModuleFactory</li><ul><li>The utility class name 'ChannelHistoryModuleFactory' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)' - line: 5</li></ul><li>SlackJSONBlockFormatter</li><ul><li>The utility class name 'SlackJSONBlockFormatter' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)' - line: 8</li></ul><li>SlackSessionFactory</li><ul><li>The utility class name 'SlackSessionFactory' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)' - line: 8</li></ul></ul><li>While Loops Must Use Braces</li><ul><li>SlackResponseHandler</li><ul><li>Avoid using while statements without curly braces - line: 42</li></ul><li>SlackWebSocketSessionImpl</li><ul><li>Avoid using while statements without curly braces - line: 437</li></ul></ul></ul></ul><br/>
</body>
</html>
Loading