def edit_weebhook(): webhook = DiscordWebhook(url='your webhook url', content='Webhook content before edit') sent_webhook = webhook.execute() webhook.content = 'After Edit' sleep(10) sent_webhook = webhook.edit(sent_webhook)
def push(content, webhook, options={}, files=[]): if isinstance(content, str): content = [content] webhook = DiscordWebhook(url=webhook) webhook.avatar_url = options.get('avatar_url') webhook.username = options.get('username') for file in files: webhook.add_file(file=file['data'], filename=file['name']) for msg in content: webhook.content = msg webhook.execute()
async def send_msg(msg, force_notify=False, file=None): try: webhook_url = os.getenv("DISCORD_WEBHOOK_URL") webhook_mention_user_id = os.getenv("DISCORD_MENTION_USER_ID") webhook_mention_role_id = os.getenv("DISCORD_MENTION_ROLE_ID") webhook = DiscordWebhook(url=webhook_url, rate_limit_retry=True) # Add the portal name. msg = "**{}**: {}".format(os.getenv("SKYNET_SERVER_API"), msg) if file and isinstance(file, str): is_json = is_json_string(file) content_type = "application/json" if is_json else "text/plain" ext = "json" if is_json else "txt" filename = "{}-{}.{}".format( CONTAINER_NAME, datetime.utcnow().strftime("%Y-%m-%d-%H:%M:%S"), ext) skylink = upload_to_skynet(file, filename, content_type=content_type) if skylink: msg = "{} {}".format(msg, skylink) # append skylink to message else: webhook.add_file(file=io.BytesIO(file.encode()), filename=filename) if force_notify and (webhook_mention_user_id or webhook_mention_role_id): webhook.allowed_mentions = { "users": [webhook_mention_user_id], "roles": [webhook_mention_role_id], } msg = "{} /cc".format(msg) # separate message from mentions if webhook_mention_role_id: msg = "{} <@&{}>".format(msg, webhook_mention_role_id) if webhook_mention_user_id: msg = "{} <@{}>".format(msg, webhook_mention_user_id) webhook.content = msg webhook.execute() print("msg > " + msg) # print message to std output for debugging purposes except: print("Failed to send message!") print(traceback.format_exc())
def hook(content, name, files=[], username=None, avatar_url=None): if current_app.debug: name = 'debug' if isinstance(content, str): content = [content] links = webhooks.get(name) if isinstance(links, str): links = [links] for link in links: webhook = DiscordWebhook(link) webhook.username = username webhook.avatar_url = avatar_url for file in files: webhook.add_file(file=file['data'], filename=file['name']) for msg in content: webhook.content = msg webhook.execute()
def _main(self): #Trucs print(f'[{time.asctime(time.localtime())}] Téléchargement du fichier EDT') try: with urllib.request.urlopen(self._URL_ENT,timeout=HTTP_TIMEOUT) as f: newedt = f.read().decode('utf-8') except: print("\tErreur au téléchargement de l'edt") else: print("\tSomme de controle md5 du fichier téléchargé") newcheck = hashlib.md5(newedt.encode()).hexdigest() print(f'\t{newcheck}') if(newcheck != self._lastcheck): if(self._lastcheck != None): webhook = DiscordWebhook(url=self._EDT_WEBHOOK,allowed_mentions=self._MENTION); webhook.content = "@everyone" embed = DiscordEmbed(title='Emploi du temps',description="L'emploi du temps à changé") webhook.add_embed(embed); webhook.execute(); self._lastcheck = newcheck self._scheduler.enter(self._EDT_REFRESH,1,self._main)
embed.add_embed_field(name='Author', value=str(e.author)) embed.add_embed_field(name='Date', value=str(aslocaltimestr(e.date))) embed.add_embed_field(name='Revision', value=str(e.revision)) embed.add_embed_field(name='Commit Message', value=str(e.msg)) webhook.add_embed(embed) #adds embed to the webhook # Write to changelog.txt outfile.write("Author: " + e.author + '\n') outfile.write("Date: " + aslocaltimestr(e.date) + '\n') outfile.write("Revision #" + str(e.revision) + '\n') outfile.write(e.msg + '\n') outfile.write('\n') if commitMadeToday == False: # If no changes were made today, say so in the changelog. webhook.content = "No changes today." outfile.write("No changes today.\n") break if e.date.date() != today: #delete all previous day's info from changelog outfile.truncate() #cut out extra newline at EOF outfile.truncate(outfile.tell() - 2) # Send stuff to Pastebin and Twitter url = pb.create_paste_from_file('./changelog.txt', 0, str(today.strftime("%m/%d/%Y")) + " Changelog", "N") api.update_status(str(today.strftime("%m/%d/%Y")) + " changelog: " + url,