tunaki / chatexchange Goto Github PK
View Code? Open in Web Editor NEWJava API for StackExchange chat
Java API for StackExchange chat
For SOBotics/Guttenberg#123, we need to get a link to a user's profile. As a workaround, we could build it by using the user-ID and Room.getChatHost()
(which we had to map manually, because ChatHost.getName()
is not public), but having User.getProfileLink()
would be much cleaner.
In this line, we need to send the link to the user's profile, who has posted the feedback to a plagiarism-report. In the current version of ChatExchange, we only get the strings stack_overflow
, stack_exchange
or meta_stack_exchange
instead of the actual hostname. That's why we had to write this ugly workaround:
public static String getChatHostAsString(ChatHost host) {
switch (host) {
case STACK_OVERFLOW:
return "stackoverflow.com";
case STACK_EXCHANGE:
return "stackexchange.com";
case META_STACK_EXCHANGE:
return "meta.stackexchange.com";
default:
return "stackoverflow.com";
}
}
https://meta.stackexchange.com/q/307647/347985
It looks like the library is using OpenID. We need to replace it with the e-mail-based authentication.
If we need help, Tim Post is inviting us to contact SE.
When I try to listen to the events UserMentionedEvent
and MessagePostedEvent
, I keep getting the following exception when the UserMentionedEvent
is happening:
ERROR [Room:254] 2017-03-18 18:17:19,840 - Couldn't execute task
java.util.concurrent.CompletionException: java.lang.UnsupportedOperationException: JsonNull
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1592)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.UnsupportedOperationException: JsonNull
at com.google.gson.JsonElement.getAsLong(JsonElement.java:230)
at fr.tunaki.stackoverflow.chat.Room.lambda$send$11(Room.java:279)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
... 7 more
You can see my code in Guttenberg's branch feature/81-global-alive-command
: https://github.com/SOBotics/Guttenberg/tree/feature/81-global-alive-command
SO returns
"The openid.return_to parameter... does not match the actual URL ",
Switching all http
to https
in the StackExchangeClient.siteLogin
seems to solve this problem
private void siteLogin(String host) throws IOException {
Response response = httpClient.get("https://" + host + "/users/login?returnurl=" + URLEncoder.encode("https://" + host + "/", "UTF-8"), cookies);
String fkey = response.parse().select("input[name='fkey']").val();
response = httpClient.post("https://" + host + "/users/authenticate", cookies, "fkey", fkey, "openid_identifier", openIdProvider);
Document document = response.parse();
// confirmation prompt?
if (response.url().toString().startsWith("https://openid.stackexchange.com/account/prompt")) {
LOGGER.trace("Confirmation prompt \n" + document.html());
String session = document.select("input[name='session']").first().val();
fkey = document.select("input[name='fkey']").first().val();
Response promptResponse = httpClient.post("https://openid.stackexchange.com/account/prompt/submit", cookies, "session", session, "fkey", fkey);
document = promptResponse.parse();
LOGGER.trace("Confirmation prompt response \n" + document.html());
}
// when the account doesn't exist on this site, confirm its creation
if (!document.select("form[action='/users/openidconfirm']").isEmpty()) {
LOGGER.debug("Account doesn't exist on target site '{}', confirming new account", host);
String session = document.select("input[name='s']").first().val();
fkey = document.select("input[name='fkey']").first().val();
Response newAccountResponse = httpClient.post("https://" + host + "/users/openidconfirm", cookies, "s", session, "fkey", fkey);
LOGGER.trace("New account confirmation response \n" + newAccountResponse.parse().html());
}
// check logged in
Response checkResponse = httpClient.get("https://" + host + "/users/current", cookies);
if (checkResponse.parse().getElementsByClass("js-inbox-button").first() == null) {
LOGGER.debug(response.parse().html());
throw new IllegalStateException("Unable to login to Stack Exchange.");
}
}
Problem retrieving plain message after SE change of response
See:
https://chat.stackoverflow.com/transcript/message/38538245#38538245
The code that needs to be changed is here:
It should be something similar to:
Elements ms = documentHistory.select (".message-source");
String plainContent = ms.get(0).ownText();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.