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

Add @everyone example #521

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TheLastGimbus
Copy link
Contributor

I created simple example which can bring Discord's @everyone capabilyty to messenger. I often use it myself.
But I'm not familliar with v2, and I couldn't find any good way to fetch all users from fbchat.Group object. There is a GroupData, but how to get it?

@TheStaticTurtle
Copy link

TheStaticTurtle commented Jan 24, 2020

I have done a similar thing for an old version of fbchat here's my code but I'm not sure if it will work:

class ListenBot(fbchat.Client):
	def onMessage(self, author_id, message_object, thread_id, thread_type, ts, metadata, msg,**kwargs):
		# @everyone: NORMAL mode
		if message_object.text and "@everyone bot" not in message_object.text and message_object.text and "@everyone" in message_object.text and thread_type == ThreadType.GROUP:
			group  = client.fetchThreadInfo(thread_id)[thread_id]
			author = self.fetchUserInfo(author_id)[author_id].name

			logger.info('@everyone in '+str(group.name)+" by: "+author)

			mentions = []
			text = "@everyone bot calling: "
			for i in group.participants:
				usertag = "@"+self.fetchUserInfo(i)[i].name
				mstart = len(text)
				text += usertag+ " / "
				mlen = len(usertag)

				mentions.append(Mention(str(i), offset=mstart, length=mlen))

			text = text[:-3]
			self.send(Message(text=text, mentions=mentions), thread_id=thread_id, thread_type=thread_type)

@kapi2289
Copy link
Contributor

Hey, please look at my implementation 😉 https://github.com/kapi2289/fb-everyone-bot It doesn't send all names, it just sends "@everyone" message, that mentions everyone in the group.

@madsmtm
Copy link
Member

madsmtm commented Jan 24, 2020

To fetch a fbchat.GroupData from a fbchat.Group, use Client.fetch_thread_info, or preferably, make your own caching implementation.

Sorry if it's not very clear yet what's going on, still working on getting everything sorted out properly.

@madsmtm madsmtm added this to In progress in v2 via automation Jan 24, 2020
@madsmtm
Copy link
Member

madsmtm commented Jan 24, 2020

But I think I like @kapi2289's idea better, where you don't send all names, you just send an "@everyone" message with a bunch of mentions

@atbuy
Copy link

atbuy commented Oct 21, 2020

I also made one with a more simpler mentioning method where each user is tagged as 1 2 3 ... and you can use @exclude and @include if you don't want to be tagged or if you changed your mind after using @exclude. Should I create a pull request or is it not needed?

@TheLastGimbus
Copy link
Contributor Author

Right now, we're not even sure if this repo will be maintained and will 2.0 look the same as it is now, so I would wait with "examples" PRs for it to settle 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
v2
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

5 participants