def send_message(webhookurl, subreddit, link, image, text): """Send a webhook message to a given discord server channel. Args: webhookurl (str): A discord webhook URL subreddit (str): The subreddit concerning the title link (str): Link to the main reddit post with more data image (str): Link to the imgur graph image text (str): Formatted text table to be shown in the webhook """ webhook = DiscordWebhooks(webhookurl) webhook.set_content(title="/r/%s Moderator Actions" % subreddit) webhook.set_image(url=image) webhook.send() #sending two webhooks is the only way that the text is formatted nicely #on both mobile and desktop with the image #this is because discord's CSS is really shitty. webhook = DiscordWebhooks(webhookurl) webhook.set_content(content=link, description=text) webhook.set_footer( text= 'jwnskanzkwk#9757\nhttps://github.com/jwansek/SubredditModActionsLog', icon_url= 'https://avatars1.githubusercontent.com/u/37976823?s=460&u=1739eabb8af515eccf259a9eb5ad7f44ac6aed85&v=4' ) webhook.send()
def test_set_image(self): """ Tests the set_image method and ensures the data gets added to the payload. """ webhook = DiscordWebhooks('webhook_url') webhook.set_content(content='Montezuma') webhook.set_image( url='https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') expected_payload = \ { 'content': 'Montezuma', 'embeds': [ { 'fields': [], 'image': { 'url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, 'author': {}, 'thumbnail': {}, 'footer': {}, } ] } self.assertEquals(webhook.format_payload(), expected_payload)
def insta_usr(): instagram = Instagram() # authentication supported instagram.with_credentials(username, password) instagram.login() account = instagram.get_account(usr) print(f"\t{account}") server = DiscordWebhooks(webhook_url) try: server.set_image(url=account.profile_pic_url) server.add_field(name="UserName : "******"Hacking is not a trick. It's an state of mind :)") server.set_author(name="HackersBrain Instagram Analyser Bot", url="http://gauravraj.gq/", icon_url="https://source.unsplash.com/35x35/?man") server.add_field(name="Full Name : ", value=account.full_name) server.add_field(name="Bio : ", value=account.biography) server.add_field(name="No. of Posts : ", value=account.media_count) server.add_field(name="No. of Followers : ", value=account.followed_by_count) server.add_field(name="No. of Follows : ", value=account.follows_count) server.add_field(name="Is Private : ", value=account.is_private) server.add_field(name="Is Verified : ", value=account.is_verified) server.send() print(Fore.GREEN + "\t Message Sent Successfully...\n" + Style.RESET_ALL) except KeyboardInterrupt as key_err: print(" Exiting Program... \tProject by : HackersBrain\n") except Exception as err: print(f"\n {err}\n Exiting Program... \tProject by : HackersBrain\n")
def test_complex_embed(self): """ Tests a combination of all methods to form a complex payload object. """ webhook = DiscordWebhooks('webhook_url') webhook.set_content(content='Montezuma', title='Best Cat Ever', description='Seriously', \ url='http://github.com/JamesIves', color=0xF58CBA, timestamp='2018-11-09T04:10:42.039Z') webhook.set_image( url='https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') webhook.set_thumbnail( url='https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') webhook.set_author( name='James Ives', url='https://jamesiv.es', icon_url= 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') webhook.set_footer( text='Footer', icon_url= 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4') webhook.add_field(name='Field', value='Value!') self.maxDiff = None expected_payload = \ { 'content': 'Montezuma', 'embeds': [ { 'title': 'Best Cat Ever', 'description': 'Seriously', 'url': 'http://github.com/JamesIves', 'color': 16092346, 'timestamp': '2018-11-09T04:10:42.039Z', 'fields': [ { 'name': 'Field', 'value': 'Value!', 'inline': False } ], 'image': { 'url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, 'author': { 'name': 'James Ives', 'url': 'https://jamesiv.es', 'icon_url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, 'thumbnail': { 'url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, 'footer': { 'text': 'Footer', 'icon_url': 'https://avatars1.githubusercontent.com/u/10888441?s=460&v=4' }, } ] } self.assertEquals(webhook.format_payload(), expected_payload)
def sendMessage(self, Message): if 'description' not in Message: raise ValueError('Discord messages requires a description') if 'content' not in Message: Message['content'] = '' if 'title' not in Message: Message['title'] = '' if 'color' not in Message: Message['color'] = 0xFFFFFF if 'author' not in Message: Message['author'] = {} if 'name' not in Message['author']: Message['author']['name'] = '' if 'url' not in Message['author']: Message['author']['url'] = '' if 'icon_url' not in Message['author']: Message['author']['icon_url'] = '' if 'footer' not in Message: Message['footer'] = {} if 'text' not in Message['footer']: Message['footer']['text'] = '' if 'icon_url' not in Message['footer']: Message['footer']['icon_url'] = '' message = DiscordWebhooks(self.webhook_url) message.set_content(color=Message['color'], content=Message['content'], description=Message['description'], title=Message['title']) message.set_footer(text=Message['footer']['text'], icon_url=Message['footer']['icon_url']) message.set_author(url=Message['author']['url'], name=Message['author']['name'], icon_url=Message['author']['icon_url']) if 'image' in Message: message.set_image(url=Message['image']) if not self.dry_run: message.send()