Git Product home page Git Product logo

chatexchange's People

Contributors

danbopes avatar dependabot[bot] avatar greenkeeper[bot] avatar oaphi avatar samliew avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

makyen

chatexchange's Issues

404 error when trying to get the event type or target user id of a message

I am getting a 404 error when trying to get the eventType or targetUserId of a message.

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

HTTPError: Response code 404 (Not Found)
    at Request.<anonymous> (/home/runner/nlnCommentBot/node_modules/got/dist/source/as-promise/index.js:118:42) {
  code: '***_***_***_***_********',
  timings: {
    start: *************,
    socket: *************,
    lookup: *************,
    connect: *************,
    secureConnect: *************,
    upload: *************,
    response: *************,
    end: *************,
    error: undefined,
    abort: undefined,
    phases: {
      wait: *,
      dns: **,
      tcp: **,
      tls: **,
      request: *,
      firstByte: **,
      download: *,
      total: ***
    }
  }
}

I replaced a bunch of stuff with * since I do not know if they are sensitive.

const fetch = require("node-fetch")
const Client = require("chatexchange");
const { ChatEventType } = require("chatexchange");

const botEmail = process.env.botEmail
const botPassWord = process.env.botPassWord
const API_KEY = process.env.Key; // Your API_KEY
const Access_Token = process.env.Token; // Your Access_Token
const Site_Name = 'stackoverflow'; // Change site name if needed
const Room_ID = '167908'; // Room to send message

const main = async () => {
  const client = new Client['default']("stackoverflow.com");

  async function getComments() {
    const response = await fetch(`https://api.stackexchange.com/2.2/comments?page=1&pagesize=100&order=desc&sort=creation&filter=!4(lY7*YmhBbS4j1g_&site=stackoverflow&key=${API_KEY}`)
    const data = await response.json()

    return data
  }

  async function filterComments() {
    const result = await getComments()
    const comments = result.items
    const quota = result.quota_remaining
  
    const thanksRegex = new RegExp(`((?:^)@(\\w+)\\b\\s)?thank([\\w.,!\']*)?(\\s[\\w{1,8},.@!:\\-)]*)?(\\s[\\w{1,8},.@!:\\-)]*)?(\\s[\\w{1,8},.@!:\\-)]*)?`)
    const gladRegex = new RegExp(`glad(?:\\sto\\shelp|hear)?`)
    const goodSolutionRegex = new RegExp("(appreciate|perfect|awesome|amazing|excellent)(?:,|\w{1,2})?(\\s(?:solution|example)?)?")
    const solveRegex = new RegExp("solv(\\w{1,3})(\\s(\w{2,5}))\\s(\\w{1,9})?")
    const upvoteRegex = new RegExp("(\\w{1,8}\\s)?up(?:\\s)?vote\\s(\\w{0,8})?\\s(\\w{0,8})?")
    const workRegex = new RegExp("(\\w{1,5}([\\w{,2}\']*)\\s)?work([\\w*{0,3}!.]*)?(\\s[:\\-)+=.}]*)?")
    const saveRegex = new RegExp("save(\\w{1,3})?\\s(\\w{0,4})\\s([\\w{0,6}.!:\\-)]*)?")
    const thanksButNotRegex = new RegExp("([\\w{1,8},.@!:)]*\\s)?(love|cheers|great)(\\s[\\w{1,8},.@!:)]*)?")
    const smilyFaceRegex = new RegExp(":\\)| :-\\)|;\\)")

    const butRegex = new RegExp("not|unfortunate|but|require|need|persists")
    const dontRegex = new RegExp("\\b(doesn|don|didn|couldn|can|isn)(['’])?(\\w{1,2})?\\b")
    const questionMarkRegex = new RegExp("[?]")

    for (let i = 0; i < comments.length; i++) {
      const thisComment = comments[i].body_markdown.toLowerCase();
      let score = 0
  
      if (thisComment.match(thanksRegex)) {
        score += 1
      }
  
      if (thisComment.match(gladRegex)) {
        score += 1
      }
  
      if (thisComment.match(goodSolutionRegex)) {
        score += 1
      }
  
      if (thisComment.match(solveRegex)) {
        score += 1
      }
  
      if (thisComment.match(upvoteRegex)) {
        score += 1
      }
  
      if (thisComment.match(workRegex)) {
        score += 1
      }
  
      if (thisComment.match(saveRegex)) {
        score += 1
      }
  
      if (thisComment.match(smilyFaceRegex)) {
        score == 1
      }
  
      if (thisComment.match(thanksButNotRegex)) {
        score += 1
      }

      if (thisComment.match(butRegex)) {
        score -= 1
      }

      if (thisComment.match(dontRegex)) {
        score -= 1
      }

      if (thisComment.match(questionMarkRegex)) {
        score -= 1
      }

      if (score > 0) {
       // sendsa a message
        client.send(`${thisComment} \n Score: ${score}`)
      }
    }
  }

  
  await client.login(botEmail, botPassWord);

  const me = await client.getMe();

  const myProfile = await client.getProfile(me);

  const { roomCount } = myProfile;
  console.log(`Rooms I am in: ${roomCount}`);

  const room = client.getRoom(Room_ID);

  const joined = await client.joinRoom(room);

  // setTimeout(filterComments(), 60000) // 60000 is 1 minute
  
  if(joined) {
    room.on("message", async (msg) => {

        const { eventType, targetUserId } = msg;

        if (eventType === ChatEventType.USER_MENTIONED && targetUserId === me.id) {
            await msg.reply(`Hi @${message.user}. Unfortently I dont have any commands (including feedback) as of now.`);
            console.log("Got Message", msg);
        }
    });

    // Connect to the room, and listen for new events
    await room.watch();
    return;
  }

  await client.logout();
};

main();

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The devDependency @babel/cli was updated from 7.7.7 to 7.8.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Rollout of the new top navbar broke cookie login

The recent rollout of the new navbar removed the my-profile CSS class from the logged-in main page on a given host subsequently breaking the ability of the package to use the loginCookie method that relied on it for confirmation of a successful login. Working on a solution.

The example does not work

The example in the README.md file does not work. On line 9 I get the following error:

/home/runner/nlnCommentBot/index.js:9
  const myClient = new Client("stackoverflow.com");
                   ^

ReferenceError: Client is not defined
    at main (/home/runner/nlnCommentBot/index.js:9:20)
    at Object.<anonymous> (/home/runner/nlnCommentBot/index.js:54:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)

I made sure I copied everything correctly and installed the library. The only thing I changed was the login to my own account. My GH repo.

Ability to make the bot leave rooms

Ability to make a bot leave a room, or all the rooms:

POST https://chat.stackexchange.com/chats/leave/<room_id>
{
  quiet: true
  fkey: fkey
}
POST https://chat.stackexchange.com/chats/leave/all
{
  quiet: true
  fkey: fkey
}

Error thrown when fetching/parsing list of room users

I think this has to do with the phantom user (community perhaps?)

Screenshot_2022-09-09_090938

Error message:

/app/node_modules/chatexchange/dist/Browser.js:320
        const userId = parseInt($userDiv.attr("href").split("/")[2], 10);
                                                      ^
 
 TypeError: Cannot read properties of undefined (reading 'split')
     at Browser.getTranscript (/app/node_modules/chatexchange/dist/Browser.js:320:54)
     at processTicksAndRejections (node:internal/process/task_queues:96:5)
     at async WebsocketEvent._Message_scrapeTranscript (/app/node_modules/chatexchange/dist/Message.js:127:59)
     at async lazy (/app/node_modules/chatexchange/dist/utils.js:34:5)

Update GitHub pages reference & republish

@samliew - I was poking around the repo and noticed that the repo "about" points to the old Pages: danbopes.github.io/chatexchange/ whereas it should point to the https://samliew.github.io/chatexchange/.
I don't have enough privileges on the repo to update it - could you do that, please?

Other than that, after a couple of battles with outdated dependencies, the repo should be in a workable state - I will continue upgrading it and hopefully will bring it to the 1.0.0 stable release.

Unable to get a time key from a websocket request when watching a room

    @Oaphi Thanks. Now I get a different error with something else.
const botEmail = process.env.botEmail
const botPassWord = process.env.botPassWord

const Client = require("chatexchange");

const { ChatEventType } = require("chatexchange");

const main = async () => {
  const client = new Client['default']("stackoverflow.com");
  
  await client.login(botEmail, botPassWord);

  const me = await client.getMe();

  const myProfile = await client.getProfile(me);

  const { roomCount } = myProfile;
  console.log(`Rooms I am in: ${roomCount}`);

  const room = client.getRoom(167908);

  room.ignore(ChatEventType.FILE_ADDED);

  const joined = await client.joinRoom(room);
  if(joined) {
    room.on("message", async (msg) => {
        console.log("Got Message", msg);

        const { eventType, targetUserId } = msg;

        if (eventType === ChatEventType.USER_MENTIONED && targetUserId === me.id) {
            await msg.reply("Hello World!");
        }

        if(eventType === ChatEventType.USER_LEFT) {
            await msg.send("See you around!", room);
        }
    });

    // Leave the room after five minutes
    setTimeout(async () => {
        await room.sendMessage("Bye everyone!");
        await client.leaveRoom(room);
    }, 3e5);

    // Connect to the room, and listen for new events
    await room.watch();
    return;
  }

  await client.logout();
};

main();
Rooms I am in: 4
/home/runner/nlnCommentBot/node_modules/chatexchange/dist/Browser.js:308
            throw new ChatExchangeError_1.default(`missing time key for room ${roomid}\n\nTime keys\n${report}`);
                  ^

ChatExchangeError: missing time key for room 167908

Time keys
167908 : missing
    at Browser.watchRoom (/home/runner/nlnCommentBot/node_modules/chatexchange/dist/Browser.js:308:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Client.watch (/home/runner/nlnCommentBot/node_modules/chatexchange/dist/Client.js:334:20)
    at async Room.watch (/home/runner/nlnCommentBot/node_modules/chatexchange/dist/Room.js:178:52)

Originally posted by @not-a-ethan in #204 (comment)

Add a proxy method for sending a message to the Message class & fix README example

    @Oaphi Played around with it and Im getting another error.
/home/runner/nlnCommentBot/index.js:36
            msg.send("See you around!", room);
                ^

TypeError: msg.send is not a function
    at Room.<anonymous> (/home/runner/nlnCommentBot/index.js:36:17)
    at Room.emit (node:events:527:28)
    at Room.emit (node:domain:475:12)
    at WebSocket.<anonymous> (/home/runner/nlnCommentBot/node_modules/chatexchange/dist/Client.js:350:25)
    at WebSocket.emit (node:events:527:28)
    at WebSocket.emit (node:domain:475:12)
    at Receiver.receiverOnMessage (/home/runner/nlnCommentBot/node_modules/ws/lib/websocket.js:1178:20)
    at Receiver.emit (node:events:527:28)
    at Receiver.emit (node:domain:475:12)

Originally posted by @not-a-ethan in #204 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.