-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import discord | ||
import json | ||
import asyncio | ||
from threading import Thread | ||
import v5path | ||
from EGAM import EGAM | ||
|
||
intents = discord.Intents.default() | ||
client = discord.Client(intents = intents) | ||
tree = discord.app_commands.CommandTree(client) | ||
|
||
ipath=v5path.ipath | ||
ipath2=v5path.ipath2 | ||
BOTTOKEN=v5path.BOTTOKEN | ||
egam=EGAM(bot_token=BOTTOKEN) | ||
|
||
@client.event | ||
async def on_ready(): | ||
print(f'This is /call! {client.user}') | ||
|
||
@tree.command(name="call", description="認証したひと”全員”を追加する") | ||
async def call(interaction: discord.Interaction,データサーバーid:str=None): | ||
try: | ||
if interaction.user.guild_permissions.administrator: | ||
zenj=open(ipath) | ||
zendata = json.load(zenj) | ||
|
||
if データサーバーid==None: | ||
useridj=open(f"{ipath2}{interaction.guild_id}.json") | ||
elif データサーバーid=="all": | ||
useridj=zenj | ||
else: | ||
useridj=open(f"{ipath2}{データサーバーid}.json") | ||
userid = json.load(useridj) | ||
a=b=c=d=e=f=0 | ||
for key, value in list(userid.items()): | ||
addmember=egam.add_member(access_token=zendata[key],user_id=key,guild_id=str(interaction.guild.id)) | ||
if addmember==201: | ||
a=a+1 | ||
elif addmember==204: | ||
b=b+1 | ||
elif addmember==403: | ||
c=c+1 | ||
del (zendata[f"{key}"]) | ||
del (userid[f"{key}"]) | ||
elif addmember==429: | ||
e=e+1 | ||
elif addmember==400: | ||
f=f+1 | ||
else: | ||
d=d+1 | ||
|
||
asyncio.sleep(1)# <- TooManyRequest対策です!!おこのみの数値または必要ないなら消してください! | ||
if データサーバーid==None: | ||
json.dump(userid, open(f"{ipath2}{interaction.guild_id}.json","w")) | ||
json.dump(zendata, open(ipath,"w")) | ||
elif データサーバーid=="all": | ||
json.dump(userid, open(ipath,"w")) | ||
else: | ||
json.dump(userid, open(f"{ipath2}{データサーバーid}.json","w")) | ||
json.dump(zendata, open(ipath,"w")) | ||
|
||
await interaction.channel.send(f"リクエストが終わりました\n{a}人を追加\n{b}人は既に追加されていて\n{c}人の情報が失効済み\n{e}回TooManyRequest\n{f}人はこれ以上サーバーに参加できません\n{d}人は不明なエラーです") | ||
else: | ||
await interaction.response.send_message("管理者しか使えません", ephemeral=True) | ||
return | ||
except: | ||
await interaction.response.send_message("DMでは使えません", ephemeral=True) | ||
|
||
|
||
@tree.command(name="button", description="認証ボタンの表示") | ||
async def panel_au(interaction: discord.Interaction,ロール:discord.Role,タイトル:str=None,説明:str=None): | ||
None | ||
@tree.command(name="check", description="UserIDを使ってTokenを検索する") | ||
async def check(interaction: discord.Interaction,ユーザーid:str): | ||
None | ||
@tree.command(name="request1", description="UserIDとトークンを使って1人リクエストする") | ||
async def req1(interaction: discord.Interaction,ユーザーid:str): | ||
None | ||
@tree.command(name="delkey", description="該当ユーザーの情報を削除する") | ||
async def delk(interaction: discord.Interaction,ユーザーid:str): | ||
None | ||
@tree.command(name="datacheck", description="登録人数の確認") | ||
async def datac(interaction: discord.Interaction): | ||
None | ||
|
||
def callstart(): | ||
c = Thread(target=main) | ||
c.start() | ||
|
||
def main(): | ||
client.run(BOTTOKEN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from threading import Thread | ||
from flask import Flask, request | ||
import json | ||
import v5path | ||
from EGAM import EGAM | ||
|
||
app = Flask("app") | ||
ipath=v5path.ipath | ||
ipath2=v5path.ipath2 | ||
BOTTOKEN=v5path.BOTTOKEN | ||
|
||
CLIENT_ID = v5path.CLIENT_ID | ||
CLIENT_SECRET = v5path.CLIENT_SECRET | ||
REDIRECT_URI = v5path.REDIRECT_URI | ||
|
||
egam=EGAM(bot_token=BOTTOKEN,client_id=CLIENT_ID,client_secret=CLIENT_SECRET,redirect_uri=REDIRECT_URI) | ||
|
||
@app.route('/', methods=["GET"]) | ||
def index(): | ||
try: | ||
code = request.args.get('code', '') | ||
if code == "": | ||
return | ||
state = request.args.get('state', '').split("=") | ||
serverstate=int(state[0],16) | ||
rolestate=int(state[1],8) | ||
try: | ||
serveridj = open(f"{ipath2}{serverstate}.json") | ||
except: | ||
return | ||
|
||
gettoken= egam.get_token(code) | ||
token = gettoken['access_token'] | ||
getuser = egam.get_user(token) | ||
user = getuser["id"] | ||
name = getuser["username"] | ||
addrole=egam.add_role(user_id=user,guild_id=str(serverstate),role_id=str(rolestate)) | ||
if not addrole==204: | ||
return f"<h1>ロールの付与に失敗しました<br>Botがロールを付与できる状態か確認してください<br>Botのロールが付与したいロールの1つ上に置かれていない場合や、管理権限に2段階認証が必要になっている場合ロールが付与できません!</h1>" | ||
|
||
serverid=json.load(serveridj) | ||
useridj=open(ipath) | ||
userid = json.load(useridj) | ||
|
||
if not user in serverid.keys(): | ||
serverid.update({user:f"{len(userid)}"}) | ||
json.dump(serverid, open(f"{ipath2}{serverstate}.json","w")) | ||
|
||
if not token in userid.values(): | ||
userid.update({user:token}) | ||
json.dump(userid, open(f"{ipath}","w")) | ||
|
||
except Exception as e: | ||
return f"<h1>エラー : {e}</h1>" | ||
|
||
return f"<h1>登録成功! {name}さんよろしく!</h1>" | ||
|
||
def run(): | ||
app.run(debug=False,host="0.0.0.0") | ||
|
||
def start(): | ||
t = Thread(target=run) | ||
t.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import discord | ||
import json | ||
import time | ||
from ninFlaskV5 import start | ||
from call import callstart | ||
import v5path | ||
from EGAM import EGAM | ||
|
||
intents = discord.Intents.default() | ||
client = discord.Client(intents = intents) | ||
tree = discord.app_commands.CommandTree(client) | ||
|
||
ipath=v5path.ipath | ||
ipath2=v5path.ipath2 | ||
BOTTOKEN=v5path.BOTTOKEN | ||
authurl=v5path.authurl | ||
egam=EGAM(bot_token=BOTTOKEN) | ||
|
||
@client.event | ||
async def on_ready(): | ||
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='認証ボタン')) | ||
print(f'Thankyou for running! {client.user}') | ||
await tree.sync() | ||
|
||
@tree.command(name="button", description="認証ボタンの表示") | ||
async def panel_au(interaction: discord.Interaction,ロール:discord.Role,タイトル:str="こんにちは!",説明:str="リンクボタンから登録して認証完了"): | ||
try: | ||
if interaction.user.guild_permissions.administrator: | ||
embed = discord.Embed(title=タイトル,description=説明,color=discord.Colour.blue()) | ||
button = discord.ui.Button(label="登録リンク", style=discord.ButtonStyle.primary, url=authurl+f"&state={(hex(interaction.guild_id)).upper()[2:]}={(oct(ロール.id)).upper()[2:]}") | ||
view = discord.ui.View() | ||
view.add_item(button) | ||
await interaction.response.send_message("made by ```.taka.``` thankyou for running!!!", ephemeral=True) | ||
try: | ||
f=open(f"{ipath2}{interaction.guild.id}.json") | ||
f2 = json.load(f) | ||
except: | ||
f = open(f"{ipath2}{interaction.guild.id}.json","w") | ||
f.write('{}') | ||
f.close() | ||
try: | ||
await interaction.channel.send(embed = embed, view = view) | ||
except: | ||
await interaction.channel.send("メッセージの送信に失敗しました") | ||
return | ||
else: | ||
await interaction.response.send_message("管理者しか使えません", ephemeral=True) | ||
return | ||
except: | ||
await interaction.response.send_message("DMでは使えません", ephemeral=True) | ||
|
||
|
||
@tree.command(name="call", description="認証したひと”全員”を追加する") | ||
async def call(interaction: discord.Interaction,データサーバーid:str=None): | ||
await interaction.response.send_message("登録されたユーザーを追加中です...") | ||
|
||
|
||
@tree.command(name="check", description="UserIDを使ってアクセストークンを検索する") | ||
async def check(interaction: discord.Interaction,ユーザーid:str): | ||
try: | ||
if interaction.user.guild_permissions.administrator: | ||
useridj=open(ipath) | ||
userid = json.load(useridj) | ||
try: | ||
token=(userid[f"{ユーザーid}"]) | ||
await interaction.response.send_message(f"該当ユーザーのトークンは```{token}```です\nUserID:```{ユーザーid}```", ephemeral=False) | ||
|
||
except: | ||
await interaction.response.send_message("ユーザー情報が見つかりませんでした", ephemeral=False) | ||
|
||
else: | ||
await interaction.response.send_message("管理者しか使えません", ephemeral=True) | ||
return | ||
except: | ||
await interaction.response.send_message("DMでは使えません", ephemeral=True) | ||
|
||
|
||
@tree.command(name="request1", description="UserIDとトークンを使って1人リクエストする") | ||
async def req1(interaction: discord.Interaction,ユーザーid:str): | ||
try: | ||
if interaction.user.guild_permissions.administrator: | ||
useridj=open(ipath) | ||
userid = json.load(useridj) | ||
try: | ||
token=(userid[f"{ユーザーid}"]) | ||
addmember=egam.add_member(access_token=token,user_id=ユーザーid,guild_id=str(interaction.guild_id)) | ||
print(addmember) | ||
if addmember==201: | ||
await interaction.response.send_message("該当のユーザーを追加しました") | ||
elif addmember==204: | ||
await interaction.response.send_message("該当のユーザーは既に追加されています") | ||
elif addmember==403: | ||
await interaction.response.send_message("該当ユーザーの保存情報は失効しています") | ||
elif addmember==400: | ||
await interaction.response.send_message("該当ユーザーはこれ以上サーバーに参加できません") | ||
elif addmember==429: | ||
await interaction.response.send_message("429レートリミットです") | ||
|
||
else: | ||
await interaction.response.send_message("該当ユーザーの追加は失敗しました") | ||
except Exception as e: | ||
await interaction.response.send_message(f"ユーザー情報が見つかりませんでした\n{e}", ephemeral=False) | ||
else: | ||
await interaction.response.send_message("管理者しか使えません", ephemeral=True) | ||
return | ||
except: | ||
await interaction.response.send_message("DMでは使えません", ephemeral=True) | ||
|
||
|
||
@tree.command(name="delkey", description="該当ユーザーの情報を削除する") | ||
async def delk(interaction: discord.Interaction,ユーザーid:str): | ||
try: | ||
if interaction.user.guild_permissions.administrator: | ||
useridj=open(ipath) | ||
userid = json.load(useridj) | ||
try: | ||
del (userid[f"{ユーザーid}"]) | ||
json.dump(userid, open(ipath,"w")) | ||
await interaction.response.send_message(f"該当ユーザーの情報を削除しました\nUserID:```{userid}```", ephemeral=False) | ||
|
||
except: | ||
await interaction.response.send_message("ユーザー情報が見つかりませんでした", ephemeral=False) | ||
else: | ||
await interaction.response.send_message("管理者しか使えません", ephemeral=True) | ||
return | ||
except: | ||
await interaction.response.send_message("DMでは使えません", ephemeral=True) | ||
|
||
|
||
@tree.command(name="datacheck", description="登録人数の確認") | ||
async def dck(interaction: discord.Interaction): | ||
try: | ||
if interaction.user.guild_permissions.administrator: | ||
useridj=open(ipath) | ||
userid = json.load(useridj) | ||
try: | ||
i=len(userid) | ||
await interaction.response.send_message(f"{i}人のデータが登録されています") | ||
except: | ||
await interaction.response.send_message("ファイルが使えなくなっています") | ||
else: | ||
await interaction.response.send_message("管理者しか使えません", ephemeral=True) | ||
return | ||
except: | ||
await interaction.response.send_message("DMでは使えません", ephemeral=True) | ||
|
||
|
||
start() | ||
time.sleep(1) | ||
callstart() | ||
time.sleep(1) | ||
client.run(BOTTOKEN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
BOTTOKEN="Botのトークンをここに" | ||
CLIENT_ID = 'OAuth2のClientIDをここに' | ||
CLIENT_SECRET = 'OAuth2のClientSecretをここに' | ||
REDIRECT_URI = 'Flaskサーバーが建てられている場所(IPアドレスやドメイン)をここに' | ||
|
||
ipath="userdata.json のパスをここに" | ||
ipath2="サーバーID.json のフォルダーパスをここに" | ||
authurl="作ったURLをここに" |