当前位置: 首页>>代码示例>>Python>>正文


Python Figlet.read方法代码示例

本文整理汇总了Python中pyfiglet.Figlet.read方法的典型用法代码示例。如果您正苦于以下问题:Python Figlet.read方法的具体用法?Python Figlet.read怎么用?Python Figlet.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyfiglet.Figlet的用法示例。


在下文中一共展示了Figlet.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_message

# 需要导入模块: from pyfiglet import Figlet [as 别名]
# 或者: from pyfiglet.Figlet import read [as 别名]
async def on_message(message):
	print("'" + message.clean_content + "'")
	message_to_bot = False
	image_in_message = False
	settings = ""
	old_settings = ""
	bot_message = ""
	if not message.author.bot:
		for mention in message.mentions:
			if mention.bot:
				print("message sent to bot")
				message_to_bot = True
		print("message sent by " + message.author.name)
		if message.server:
			serverid = message.server.id
			owner = message.server.owner
			if os.path.exists("server/" +  message.server.name):
				os.rename("server/" +  message.server.name, "server/" + serverid)
			if not os.path.exists("server/" + serverid):
				os.makedirs("server/" + serverid)
				os.makedirs("server/" + serverid + "/images")
				os.makedirs("server/" + serverid + "/output")
				print("created server folder structure for " + serverid)
			if os.path.isfile("server/" + serverid + "/settings.json"):
				with open("server/" + serverid + "/settings.json", "r") as settings_file:
					settings = settings_file.read()
					settings = json.loads(settings)
			if settings != "":
				current_settings_ver = settings["version"]
			else:
				current_settings_ver = 0
			if current_settings_ver != settings_ver:
				with open("server/" + serverid + "/settings.json", "w") as settings_file:
					settings_file.write('{"version" : '+str(settings_ver)+', "farewell": false, "farewell_text": "**Hope to see you soon again, $member <3**", "greetings": false, "greetings_text" : "**Welcome $mention to __$server__**!", "fakku": true, "sadpanda": true,"animated": "'+message.server.default_role.id+'", "meme_txt": "'+message.server.default_role.id+'", "meme_img": "'+message.server.default_role.id+'", "image": "'+message.server.default_role.id+'", "say": "'+message.server.owner.top_role.id+'", "ascii": "'+message.server.default_role.id+'", "rate": true, "sleep": true, "question": true, "info": "'+message.server.default_role.id+'", "help": "'+message.server.default_role.id+'", "options": "'+message.server.owner.top_role.id+'", "slot_machine": [":pizza:", ":frog:", ":alien:", ":green_apple:", ":heart:"] }')
					print("created new settings_file")
			if message.server.me.nick:
				my_name = message.server.me.nick
			else:
				my_name = client.user.name
			if os.path.isfile("server/" + serverid + "/settings.json"):
				if current_settings_ver != settings_ver:
					old_settings = settings
			if os.path.isfile("server/" + serverid + "/settings.json"):
				with open("server/" + serverid + "/settings.json", "r") as settings_file:
					settings = settings_file.read()
					settings = json.loads(settings)
					if old_settings != "":
						for key, value in old_settings.items():
							if key != "version":
								settings[key] = old_settings[key]
						with open("server/" + serverid + "/settings.json", "w") as settings_file:
							json.dump(settings, settings_file)
							print("settings updated")
		else:
			serverid = "None"
			owner = message.author
			my_name = client.user.name
			settings = json.loads('{"slot_machine": [":pizza:", ":frog:", ":alien:", ":green_apple:", ":heart:"], "sadpanda": true, "fakku": true, "question": true }')
		if not os.path.exists("server/" + serverid + "/images/last_image.png"):
			file_download(random.choice(requests.get('https://pastebin.com/raw/90WCeZp9').text.split()), "server/" + serverid + "/images/", "last_image.png")
		with open("server/" + serverid + "/log.txt", "a") as myfile:
				if message.clean_content.endswith(".") or message.clean_content.endswith("!") or message.clean_content.endswith("?") or message.clean_content.endswith("="):
					 myfile.write(message.clean_content.replace("@", ""))
				elif message.clean_content.startswith(("?", "!", "=", "`", "´", "^", ";", "~", "+", "\/", "\\", "]", "}", ")", ":", "<")):
					print("message sent to bot")
					message_to_bot = True
				else:
					myfile.write(message.clean_content.replace("@", "") + ". ")
		for attachment in message.attachments:
			file_download(attachment["proxy_url"], "server/" + serverid + "/", "last_image.png")
			image_in_message = True
		images = re.findall('(?i)https?:\/\/.*\.(?:png|jpg|jpeg|gif)', message.content)
		for image in images:
			file_download(image, "server/" + serverid + "/", "last_image.png")
		if not message_to_bot:
			sadpanda = re.findall('(?i)https?:\/\/(?:ex|g.e-)hentai.org\/g\/(\S{6})\/(\S{10})', message.content)
			fakku = re.findall('(?i)https:\/\/(?:www\.)fakku\.net\/(?:hentai|manga)\/\S*', message.content)
			if settings["sadpanda"] == True and sadpanda:
				await client.send_typing(message.channel)
				gidlist = []
				manga_info = ""
				payload = json.loads('{"method" : "gdata", "gidlist" : [], "namespace": 1 }')
				for index, manga in enumerate(sadpanda):
					gid = int(manga[0])
					gt = manga[1]
					payload["gidlist"].append([gid, gt])
				url = 'http://g.e-hentai.org/api.php'
				header = {'Content-type' : 'application/json'}
				print("creating json request for mangas")
				ex_response = requests.post(url, data=json.dumps(payload), headers=header)
				if ex_response.status_code == 200:
					brackets = re.compile(r'(?:\(|\[|\{)[^(?:\)|\]|\})]*(?:\)|\]|\})')
					manga_info = ex_response.json()
					print(manga_info)
					for manga in manga_info["gmetadata"]:
						title_eng = re.sub(brackets, '', re.sub(brackets, '', manga["title"])).strip()
						title_jpn = re.sub(brackets, '', re.sub(brackets, '', manga["title_jpn"])).strip()
						date = datetime.datetime.fromtimestamp(
							int(manga["posted"])
						).strftime('%Y-%m-%d %H:%M')
#.........这里部分代码省略.........
开发者ID:ZerataX,项目名称:ebooks,代码行数:103,代码来源:ebooks.py


注:本文中的pyfiglet.Figlet.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。