Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
將所有輸出界面改為從json導入str
  • Loading branch information
lonnstyle committed Mar 23, 2021
1 parent 8e46239 commit 6062167
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 248 deletions.
10 changes: 7 additions & 3 deletions cmds/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from core.classes import Cog_Extension
import os
import json
from language import language as lang

lang = lang()
lang = lang.langpref()['admin']

with open('setting.json', 'r', encoding='utf8') as jfile:
jdata = json.load(jfile)
Expand All @@ -11,13 +15,13 @@
class admin(Cog_Extension):
tag = "admin"
#清除訊息
@commands.command(name='clear', aliases=['clean' , '清除'],brief="刪除聊天記錄",description="clear [指定數量]\n刪除指定數量的聊天記錄")
@commands.command(name='clear', aliases=lang['clear.aliases'],brief=lang['clear.brief'],description=lang['clear.description'])
async def clear(self,ctx,num:int):
if ctx.message.author.id == ctx.guild.owner_id:
await ctx.channel.purge(limit=num+1)
print(str(ctx.message.author)+' ---ID '+str(ctx.message.author.id)+'在 << '+str(ctx.channel.name)+' >> 頻道使用了clear指令刪除了'+str(int(num))+'個對話')
print(str(ctx.message.author)+' ---ID '+str(ctx.message.author.id)+lang['clear.cleared'].format(channel=str(ctx.channel.name),num=str(int(num))))
else:
embed = discord.embed(title="權限不足",description='本指令只提供給伺服器傭有者 \n本伺服器擁有者為 <@' + str(ctx.guild.owner_id) + '>')
embed = discord.embed(title=lang['clear.error.title'],description=lang['clear.error.description'].format(owner=self.bot.owner_id))
await ctx.send(embed=embed)

def setup(bot):
Expand Down
30 changes: 17 additions & 13 deletions cmds/baro.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
import json
import asyncio
import chinese_converter
from language import language as lang

rawDict = requests.get("https://raw.githubusercontent.com/lonnstyle/riven-mirror/dev/src/i18n/lang/zh-Hant.json")
lang = lang()
lang = lang.langpref()['baro']

rawDict = requests.get(lang['rawDict.URL'])
Dict = json.loads(rawDict.text)
Dict = Dict['messages']

class baro(Cog_Extension):
tag = "Warframe"
@commands.command(name='baro',aliases=['奸商' , 'Baro'],brief="虛空商人信息",description="查詢虛空商人Baro Ki'Teer目前狀態\t如已經抵達中繼站則會顯示所攜帶商品列表")
@commands.command(name='baro',aliases=lang['baro.aliases'],brief=lang['baro.brief'],description=lang['baro.description'])
async def baroManual(self,ctx):
url = requests.get("https://api.warframestat.us/pc/tc/voidTrader",headers={'Accept-Language':'zh','Cache-Control': 'no-cache'})
html = json.loads(url.text)
Expand All @@ -22,10 +26,10 @@ async def baroManual(self,ctx):
location = html['location']
location = chinese_converter.to_traditional(location)
stay = html['endString']
stay = stay.replace("d","天")
stay = stay.replace("h","小時")
stay = stay.replace("m","分鐘")
stay = stay.replace("s","秒")
stay = stay.replace("d",lang['baro.time.day'])
stay = stay.replace("h",lang['baro.time.hour'])
stay = stay.replace("m",lang['baro.time.minute'])
stay = stay.replace("s",lang['baro.time.second'])
for items in html['inventory']:
item = items['item']
item = item.lower()
Expand All @@ -42,19 +46,19 @@ async def baroManual(self,ctx):
name = Dict.get(name,name)
ducats = items['ducats']
credits = items['credits']
message += f"物品:{name}\n杜卡德金幣:{ducats}\t現金:{credits}\n"
message += lang['baro.item'].format(name=name,ducats=ducats,credits=credits)
message += "```"
embed = discord.Embed(title=f"Baro Ki'Teer 已經到達{location},停留時間為{stay}\t帶來的商品如下:",description=message,color=0x429990)
embed = discord.Embed(title=lang['baro.arrived'].format(location=location,stay=stay),description=message,color=0x429990)
await ctx.send(embed=embed)
if html['active'] == False:
location = html['location']
location = chinese_converter.to_traditional(location)
arrive = html['startString']
arrive = arrive.replace("d","天")
arrive = arrive.replace("h","小時")
arrive = arrive.replace("m","分鐘")
arrive = arrive.replace("s","秒")
embed = discord.Embed(description=f"Baro Ki' Teer會在{arrive}後抵達{location}",color=0x429990)
arrive = arrive.replace("d",lang['baro.time.day'])
arrive = arrive.replace("h",lang['baro.time.hour'])
arrive = arrive.replace("m",lang['baro.time.minute'])
arrive = arrive.replace("s",lang['baro.time.second'])
embed = discord.Embed(description=lang['baro.arrival'].format(arrive=arrive,location=location),color=0x429990)
await ctx.send(embed=embed)


Expand Down
117 changes: 47 additions & 70 deletions cmds/common.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,63 @@
import discord
from discord.ext import commands
from core.classes import Cog_Extension
from core.classes import Cog_Extension
import random
import json
from random import randint
import requests
import json
from random import randint
import requests
import re
import asyncio

import asyncio
from language import language as lang

lang = lang()
lang = lang.langpref()['common']

with open('setting.json', 'r', encoding='utf8') as jfile:
jdata = json.load(jfile)

emoji = requests.get("http://gist.githubusercontent.com/Vexs/629488c4bb4126ad2a9909309ed6bd71/raw/416403f7080d1b353d8517dfef5acec9aafda6c3/emoji_map.json").text
emoji = json.loads(emoji)
emoji = {x: y for y, x in emoji.items()}

emoji = requests.get("http://gist.githubusercontent.com/Vexs/629488c4bb4126ad2a9909309ed6bd71/raw/416403f7080d1b353d8517dfef5acec9aafda6c3/emoji_map.json").text
emoji = json.loads(emoji)
emoji = {x: y for y, x in emoji.items()}

class common(Cog_Extension):
class common(Cog_Extension):
tag = "common"
#ping
@commands.command(name= 'ping', aliases=['延遲' , '機器人延遲' , 'delay'],brief="測試延遲",description="顯示當前機器人處理信息的延遲值")
async def ping(self, ctx):
latency = round(self.bot.latency*1000)
red = max(0,min(int(255*(latency-50)/1000),255))
green = 255-red
color = discord.Colour.from_rgb(r=red,g=green,b=0)
embed = discord.Embed(title="當前本機延遲為",description=f'{latency} 毫秒 (ms)',color=color)
await ctx.send(embed=embed)
@commands.command(name= 'ping', aliases=lang['ping.aliases'],brief=lang['ping.brief'],description=lang['ping.description'])
async def ping(self, ctx):
latency = round(self.bot.latency*1000)
red = max(0,min(int(255*(latency-50)/1000),255))
green = 255-red
color = discord.Colour.from_rgb(r=red,g=green,b=0)
embed = discord.Embed(title=lang['ping.embed.title'],description=lang['ping.latency'].format(latency=latency),color=color)
await ctx.send(embed=embed)

#說
@commands.command(name= 'sayd', aliases=['說' , '機器人說'],brief="復讀",description="讓機器人代替你說出`msg`的內容")
@commands.command(name= 'sayd', aliases=lang['sayd.aliases'],brief=lang['sayd.brief'],description=lang['sayd.description'])
async def sayd(self,ctx,*,msg):
await ctx.message.delete()
embed=discord.Embed(description=msg,color=0x3C879C)
message = await ctx.send(embed=embed)
#此功能為開發伺服器上公告自動廣播之用
if ctx.channel.id == 820571680479903776:
await message.publish()

@commands.command(name= 'poll', aliases=['投票'],brief="發起投票",description="讓機器人發起一項投票")
async def poll(self,ctx,topic,option1,emoji1,option2,emoji2):
await ctx.message.delete()
match1 = re.match(r'<(a?):([a-zA-Z0-9\_]+):([0-9]+)>$', emoji1)
match2 = re.match(r'<(a?):([a-zA-Z0-9\_]+):([0-9]+)>$', emoji2)
if (emoji.get(emoji1,None)!=None or match1) and (emoji.get(emoji2,None)!=None or match2):
if emoji1 == emoji2 or option1 == option2:
await ctx.send(embed=discord.Embed(title="錯誤信息",description='兩個一樣你要投什麼?',color=0xff0000))
return
embed=discord.Embed(description=topic,color=0x3C879C)
embed.add_field(name=option1,value=emoji1)
embed.add_field(name=option2,value=emoji2)
message = await ctx.send(embed=embed)
await message.add_reaction(emoji1)
await message.add_reaction(emoji2)
else:
await ctx.send(embed=discord.Embed(title="錯誤信息",description='這真的是emoji嗎?'))

@commands.command(name="role",brief="新增身份組",description="新增機器人可以分發的身份組")
async def role(self,ctx,role):
if ctx.message.author.id == ctx.guild.owner_id:
for roles in ctx.guild.roles:
if roles.name == role:
embed = discord.Embed(title="已新增身份組",description=f"已新增<@&{roles.id}>")
await ctx.send(embed=embed)
with open("roles.txt","a",encoding="utf8") as role_id:
role_id.write(roles.name+'\n')

@commands.command(name="join",brief="加入身份組",description="使機器人分配身份組權限")
async def join(self,ctx,role):
await ctx.message.delete()
with open("roles.txt","r",encoding="utf8") as roles:
if (role+'\n') in roles.readlines():
for roles in ctx.guild.roles:
if roles.name == role:
await ctx.author.add_roles(roles)
message = await ctx.send(embed=discord.Embed(title="已加入身份組",description=f"<@&{roles.id}>",color=0x00ff00))
await asyncio.sleep(10)
message.delete()
else:
message = await ctx.send(embed=discord.Embed(title="加入身份組失敗",description="請確保身份組輸入無誤",color=0xff0000))
await asyncio.sleep(10)
message.delete()
embed=discord.Embed(description=msg,color=0x3C879C)
message = await ctx.send(embed=embed)
if ctx.channel.id == jdata['publish']:
await message.publish()

@commands.command(name= 'poll', aliases=lang['poll.aliases'],brief=lang['poll.brief'],description=lang['poll.description'])
async def poll(self,ctx,topic,option1,emoji1,option2,emoji2):
await ctx.message.delete()
match1 = re.match(r'<(a?):([a-zA-Z0-9\_]+):([0-9]+)>$', emoji1)
match2 = re.match(r'<(a?):([a-zA-Z0-9\_]+):([0-9]+)>$', emoji2)
if (emoji.get(emoji1,None)!=None or match1) and (emoji.get(emoji2,None)!=None or match2):
if emoji1 == emoji2 or option1 == option2:
await ctx.send(embed=discord.Embed(title=lang['poll.error.title'],description=lang['poll.error.description.same'],color=0xff0000))
return
embed=discord.Embed(description=topic,color=0x3C879C)
embed.add_field(name=option1,value=emoji1)
embed.add_field(name=option2,value=emoji2)
message = await ctx.send(embed=embed)
await message.add_reaction(emoji1)
await message.add_reaction(emoji2)
else:
await ctx.send(embed=discord.Embed(title=lang['poll.error.title'],description=lang['poll.error.description.emoji']))


def setup(bot):
bot.add_cog(common(bot))
bot.add_cog(common(bot))
55 changes: 50 additions & 5 deletions cmds/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,78 @@
from datetime import datetime,timedelta
import json
import os
import requests
import re
import discord
from language import language as lang

lang = lang()
lang = lang.langpref()['event']

with open('setting.json', 'r', encoding='utf8') as jfile:
jdata = json.load(jfile)

emojimap = requests.get("http://gist.githubusercontent.com/Vexs/629488c4bb4126ad2a9909309ed6bd71/raw/416403f7080d1b353d8517dfef5acec9aafda6c3/emoji_map.json").text
emojimap = json.loads(emojimap)
emojimap = {x: y for y, x in emojimap.items()}

class event(Cog_Extension):
tag = "common"
@commands.command(name="reactionRole", aliases=["rr"],brief="指定自動身份組訊息",description="指定可自動分發身份組的訊息")
async def rr(self,ctx,message:int):
with open("role/rr.txt","a") as rr:
rr.write(f"{message}\n")
await ctx.message.add_reaction("✅")
await ctx.message.delete(delay=5)


@commands.command(name='role', aliases=lang['role.aliases'],brief=lang['role.brief'],description=lang['role.description'])
async def role(self,ctx,role:str,emoji):
match = re.match(r'<(a?):([a-zA-Z0-9\_]+):([0-9]+)>$', emoji)
if (emojimap.get(emoji,None)!=None or match) and ctx.author.guild_permissions.administrator == True:
with open("role/roles.txt","a") as roles:
roles.write(f"{emoji},{role}\n")
await ctx.message.add_reaction("✅")
await ctx.message.delete(delay=5)
else:
await ctx.message.delete()
await ctx.send(embed=discord.Embed(title=lang['role.error.title'],description=lang['role.error.description']))

@commands.Cog.listener()
async def on_raw_reaction_add(self,payload):
roles = {}
message = []
raw = open("role/roles.txt","r")
rr = open("role/rr.txt","r")
for line in raw.readlines():
emoji,role = line.split(",")
roles[emoji] = role.replace("\n","")
for line in rr.readlines():
message.append(line.replace("\n",""))
for role in payload.member.guild.roles:
if (role.name == roles.get(payload.emoji.name) or role.name == roles.get(f"<:{payload.emoji.name}:{payload.emoji.id}>")) and str(payload.message_id) in message:
await payload.member.add_roles(role)

@commands.Cog.listener()
async def on_message(self,msg):
if str(msg.channel.type) == 'private' and msg.author != self.bot.user:
print(time_info.UTC_8() + str(msg.author) + '說:' + msg.content)
print(time_info.UTC_8() + str(msg.author) + lang['onMessage.say'] + msg.content)
fp = open('./log/' + 'Private.log', 'a',encoding='utf8')
fp.write(time_info.UTC_8() + str(msg.author) + '說:' + msg.content+'\n')
fp.write(time_info.UTC_8() + str(msg.author) + lang['onMessage.say'] + msg.content+'\n')
fp.close()
else:
if str(msg.channel.type) == 'text' and msg.author != self.bot.user:
print(time_info.UTC_8_CH() + str(msg.author) + '說:' + msg.content)
print(time_info.UTC_8_CH() + str(msg.author) + lang['onMessage.say'] + msg.content)
for items in msg.attachments:
print(items)
a = str(msg.guild)
b = str(msg.channel)
fp = open('./log/' + a + '-' + b + '.log', 'a',encoding='utf8')
fp.write(time_info.UTC_8() + str(msg.author) + '說:' + msg.content+'\n')
fp.write(time_info.UTC_8() + str(msg.author) + lang['onMessage.say'] + msg.content+'\n')
fp.close()
pass

def setup(bot):
if not os.path.exists('log'):
os.mkdir('log')
bot.add_cog(event(bot))
bot.add_cog(event(bot))
13 changes: 9 additions & 4 deletions cmds/logup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from core.classes import Cog_Extension
import os
import json
from language import language as lang

lang = lang()
lang = lang.langpref()['event']

with open('setting.json','r',encoding='utf8') as jset:
jdata = json.load(jset)

Expand All @@ -19,7 +24,7 @@ class logup(Cog_Extension):
tag = "common"
@commands.command()
async def loglist(self,ctx):
if str(ctx.author.id) == jdata['owner']:
if await self.bot.is_owner(ctx.message.author):
msg = ''
dou = 0
for i in loglist:
Expand All @@ -34,20 +39,20 @@ async def loglist(self,ctx):

@commands.command()
async def reloadlog(self,ctx):
if str(ctx.author.id) == jdata['owner']:
if await self.bot.is_owner(ctx.message.author):
global loglist,logindex
loglist = []
for logname in os.listdir('./log'):
if logname.endswith('.txt'):
loglist.append(logindex)
loglist.append(logname)
logindex += 1
await ctx.send('已重新加載')
await ctx.send(lang['reloadlog.reloaded'])
logindex = 0

@commands.command()
async def downloadlog(self,ctx,index):
if str(ctx.author.id) == jdata['owner']:
if await self.bot.is_owner(ctx.message.author):
for i in loglist:
if i == int(index):
a = 'log\\'+loglist[i+1]
Expand Down
Loading

0 comments on commit 6062167

Please sign in to comment.