fbchat icon indicating copy to clipboard operation
fbchat copied to clipboard

Add @everyone example

Open TheLastGimbus opened this issue 5 years ago • 6 comments

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?

TheLastGimbus avatar Jan 23 '20 23:01 TheLastGimbus

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)

TheStaticTurtle avatar Jan 24 '20 02:01 TheStaticTurtle

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

kapi2289 avatar Jan 24 '20 05:01 kapi2289

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 avatar Jan 24 '20 07:01 madsmtm

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

madsmtm avatar Jan 24 '20 07:01 madsmtm

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?

atbuy avatar Oct 21 '20 22:10 atbuy

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 :confused:

TheLastGimbus avatar Oct 21 '20 22:10 TheLastGimbus