Skip to content

Commit

Permalink
convert tex
Browse files Browse the repository at this point in the history
  • Loading branch information
tomru112345 committed Nov 21, 2021
1 parent bf733c9 commit 126b2f0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tokenGbot.py
token.py
85 changes: 58 additions & 27 deletions Gbot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: <encoding name> -*-
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

import discord
import subprocess
Expand All @@ -10,33 +10,37 @@
import re
import os
import glob
import token
import tokenGbot

# 自分のBotのアクセ
TOKEN = token.TOKEN
keigo_sever = token.keigo_sever
VC_ID = token.VC_ID
voice_chat_ID = token.voice_chat_ID
pubglite_VC_ID = token.pubglite_VC_ID
Text_ID = token.Text_ID
Genkai_log_ID = token.Genkai_log_ID
TOKEN = tokenGbot.TOKEN
keigo_sever = tokenGbot.keigo_sever
VC_ID = tokenGbot.VC_ID
voice_chat_ID = tokenGbot.voice_chat_ID
pubglite_VC_ID = tokenGbot.pubglite_VC_ID
Text_ID = tokenGbot.Text_ID
Genkai_log_ID = tokenGbot.Genkai_log_ID

# 接続に必要なオブジェクトを生成
client = discord.Client()

# 起動時に動作する処理


@client.event
async def on_ready():
# 起動したらターミナルにログイン通知が表示される
print('システムログ: ログインしました')

# メッセージ受信時に動作する処理


@client.event
async def on_message(message):
# シャットダウンコマンド
if message.author.bot:
pass
#コマンド
# コマンド
else:
if message.content == '#shutdown':
await message.channel.send('Shutdown now')
Expand All @@ -50,9 +54,11 @@ async def on_message(message):
print("システムログ: Word を PDF に変換します")
docx_path = "./docx/" + message.attachments[0].filename
await message.attachments[0].save(docx_path)
args = ['./word2pdf.sh', docx_path, "./pdf/" + message.attachments[0].filename[:-4] + "pdf"]
args = ['./word2pdf.sh', docx_path, "./pdf/" +
message.attachments[0].filename[:-4] + "pdf"]
subprocess.run(args)
print("./pdf/"+message.attachments[0].filename[:-4] + "pdf")
print(
"./pdf/"+message.attachments[0].filename[:-4] + "pdf")
await message.channel.send(file=discord.File("./pdf/"+message.attachments[0].filename[:-4] + "pdf"))
else:
print("エラー: 添付ファイルを用意してください")
Expand All @@ -63,9 +69,11 @@ async def on_message(message):
print("システムログ: Markdown を PDF に変換します")
md_path = "./Markdown/" + message.attachments[0].filename
await message.attachments[0].save(md_path)
args = ['./md2pdf.sh', md_path, "./pdf/" + message.attachments[0].filename[:-2] + "pdf"]
args = ['./md2pdf.sh', md_path, "./pdf/" +
message.attachments[0].filename[:-2] + "pdf"]
subprocess.run(args)
print("./pdf/"+message.attachments[0].filename[:-2] + "pdf")
print(
"./pdf/"+message.attachments[0].filename[:-2] + "pdf")
await message.channel.send(file=discord.File("./pdf/"+message.attachments[0].filename[:-2] + "pdf"))
else:
print("エラー: 添付ファイルを用意してください")
Expand All @@ -76,9 +84,11 @@ async def on_message(message):
print("システムログ: Markdown を PowerPoint に変換します")
md_path = "./Markdown/" + message.attachments[0].filename
await message.attachments[0].save(md_path)
args = ['./md2pptx.sh', md_path, "./pptx/" + message.attachments[0].filename[:-2] + "pptx"]
args = ['./md2pptx.sh', md_path, "./pptx/" +
message.attachments[0].filename[:-2] + "pptx"]
subprocess.run(args)
print("./pptx/"+message.attachments[0].filename[:-2] + "pptx")
print(
"./pptx/"+message.attachments[0].filename[:-2] + "pptx")
await message.channel.send(file=discord.File("./pptx/"+message.attachments[0].filename[:-2] + "pptx"))
else:
print("エラー: 添付ファイルを用意してください")
Expand All @@ -89,13 +99,30 @@ async def on_message(message):
print("システムログ: Markdown を Word に変換します")
md_path = "./Markdown/" + message.attachments[0].filename
await message.attachments[0].save(md_path)
args = ['./md2word.sh', md_path, "./docx/" + message.attachments[0].filename[:-2] + "docx"]
args = ['./md2word.sh', md_path, "./docx/" +
message.attachments[0].filename[:-2] + "docx"]
subprocess.run(args)
print("./docx/"+message.attachments[0].filename[:-2] + "docx")
print(
"./docx/"+message.attachments[0].filename[:-2] + "docx")
await message.channel.send(file=discord.File("./docx/"+message.attachments[0].filename[:-2] + "docx"))
else:
print("エラー: 添付ファイルを用意してください")

elif message.content.startswith("#convert md2tex"):
if message.attachments:
if message.attachments[0].filename.endswith(".md"):
print("システムログ: Markdown を tex に変換します")
md_path = "./Markdown/" + message.attachments[0].filename
await message.attachments[0].save(md_path)
args = ['./md2tex.sh', md_path, "./tex/" +
message.attachments[0].filename[:-2] + "tex"]
subprocess.run(args)
print(
"./tex/"+message.attachments[0].filename[:-2] + "tex")
await message.channel.send(file=discord.File("./tex/"+message.attachments[0].filename[:-2] + "tex"))
else:
print("エラー: 添付ファイルを用意してください")

elif message.content.startswith("#show pdf"):
sp_args = message.content.split()
print(sp_args)
Expand All @@ -105,24 +132,25 @@ async def on_message(message):
pdf_path = "./pdf/" + message.attachments[0].filename
await message.attachments[0].save(pdf_path)
img_path = "./image"
convert_from_path(pdf_path, output_folder=img_path,fmt='jpeg', output_file=message.attachments[0].filename[:-4])

convert_from_path(pdf_path, output_folder=img_path, fmt='jpeg',
output_file=message.attachments[0].filename[:-4])

result = glob.glob(os.path.join("./image", '*'))

t = 0
for i in result:
result[t] = discord.File(i)
t = t + 1

await message.channel.send(files = result[:10])
await message.channel.send(files=result[:10])
result = glob.glob(os.path.join("./image", '*'))
for i in result:
args = ['rm', i]
subprocess.run(args)
else:
print("エラー: 添付ファイルを用意してください")

#todo
# todo

elif message.content.startswith("#show docx"):
sp_args = message.content.split()
Expand All @@ -133,24 +161,27 @@ async def on_message(message):
pdf_path = "./pdf/" + message.attachments[0].filename
await message.attachments[0].save(pdf_path)
img_path = "./image"
convert_from_path(pdf_path, output_folder=img_path,fmt='jpeg', output_file=message.attachments[0].filename[:-4])

convert_from_path(pdf_path, output_folder=img_path, fmt='jpeg',
output_file=message.attachments[0].filename[:-4])

result = glob.glob(os.path.join("./image", '*'))

t = 0
for i in result:
result[t] = discord.File(i)
t = t + 1

await message.channel.send(files = result[:10])
await message.channel.send(files=result[:10])
result = glob.glob(os.path.join("./image", '*'))
for i in result:
args = ['rm', i]
subprocess.run(args)
else:
print("エラー: 添付ファイルを用意してください")

#voicechannelへの入退室アナウンス
# voicechannelへの入退室アナウンス


@client.event
async def on_voice_state_update(member, before, after):
if member.guild.id == keigo_sever and (before.channel != after.channel):
Expand All @@ -164,4 +195,4 @@ async def on_voice_state_update(member, before, after):
await alert_channel.send(msg)

# Botの起動とDiscordサーバーへの接続
client.run(TOKEN)
client.run(TOKEN)
1 change: 1 addition & 0 deletions md2tex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo docker run -it --rm -v `pwd`:/workspace k1low/alpine-pandoc-ja pandoc $1 -f markdown -o $2

0 comments on commit 126b2f0

Please sign in to comment.