Code Monkey home page Code Monkey logo

kgbicheno / kgb_edits Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 3.0 3.44 MB

A backup bot designed to dispatch emergency services alerts in cases where human agents are no longer able to do so but internet connectivity has not yet been destroyed.

License: GNU General Public License v3.0

Python 97.56% Makefile 1.08% Batchfile 1.36%
api api-client beautifulsoup4 bot discord discord-bot discord-py emergency emergency-information emergency-response feed flood human-agents python python3 qfes-alerts webscraping

kgb_edits's People

Contributors

dependabot[bot] avatar kgbicheno avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

kgb_edits's Issues

Embed links in first aid discord bod embed go to wrong location

This is most likely down to me misreading the documentation twelve times but an explicit URL in an embed field to a pdf hosted on the St John's Ambulance website redirects to another page on the same site.

Obviously there's a redirect being set up on the St John's site but this would qualify as a bug in my code.

Either I'm going to find a temporary CDN to host the files or speed up KGB_Golem to handle the hosting from my own server and hope for the best.

Any other solutions would be much appreciated.

News feeds are a mess

nrm_pull, qfes_pull, and bom_pull are too buggy to be given front-ends. That needs to change tomorrrow.

b.roll command is a mess when dealing when d>1

If AdX+B takes the form A1dX1+A2dX2 the wheels come of and an exception gets thrown with them, I need to flatten the list of lists to avoid a type mismatch over the operand. I'd had an itertools method masking the issue earlier but that had just been spewing out nonsense results.

I'd have fixed it tonight but I'm going to bed. Reference to fix is in the comments.

aid() command argument to database matching is innacurate

The first aid command in the Emergency cog (b.aid) uses a keyword-only argument to accept entire messages to parse for keywords. It splits the message into a list of words and aims to match those words against keys in a JSON file using the "in" builtin. Both the listed-argument word and the key are made lower-case as a hacky way of fuzzing the search.

It works terribly to the point of it being a bug.

"I'm having an asthma attack" returns 2 results and neither of them is the result for asthma.

Below the code is a sample of the JSON file. I have full copyright permission to display this information granted by its owner but cannot pass it on.

@commands.command()
	async def aid(self, ctx, *, arg):
		"""Searches the St John's Ambulance First Aid guides for anything that matches the text passed into the function"""
		assert isinstance(arg, str), "I'm sorry, I can only help if you tell me your situation."
		await ctx.send("Please wait a moment while I check if I have any resources for the situation")
		circumstances = split("\s", arg)
		print(circumstances)
		#TODO Add a funnel layer to catch the broadest variation of synonyms to database entries.
		with open("first_aid.json", "r", encoding="UTF-8") as repo:
			resources = json.load(repo)
		solutions = resources['items']
		outcomes = []
		for circumstance in circumstances:
			print(circumstance)
			for solution in solutions:
				print(solution)
				print(type(solution))
				#TODO I know this is a hack, need to change for i18
				#TODO This just isn't picking up obvious matches
				if circumstance.lower() in solution['situation'].lower():
					print(solution['situation'])
					print(solution['url'])
					outcomes.append((solution['situation'], solution['url'], solution['language']))
					#TODO Mirror the St John's files on my server and add a 'pretty' layer for thumbnails
		await ctx.send("I may have found something.")

		new_order = [2, 0, 1, 3, 4, 5]
		results = [outcomes[i] for i in new_order]

		#TODO reintroduce the non-English languages in a future patch when you've figured out a more streamlined way to do this.
		for result in results:
			print(results)
			print(result)
			aid = str(result[0])
			print(aid)
			linkage = str(result[1])
			print(linkage)
			language = str(result[2])
			print(language)
			if language != "English":
				break
			else:
				embed = discord.Embed(title="First Aid Card", type="rich", url='https://stjohn.org.au/first-aid-facts',
				                      description="Based on your description, this is what my database has returned",
				                      color=0xff0000)
				embed.set_author(name="Brook Newlsy",
				                 url='https://discordapp.com/oauth2/authorize?client_id=695245576475902002&permissions=8&scope=bot',
				                 icon_url='https://i.imgur.com/bQSgvV1.jpg')
				embed.set_thumbnail(url='https://i.imgur.com/KP6B8zx.png')
				embed.add_field(name="Situation", value=aid, inline=True)
				embed.add_field(name="Reference",
				                value=linkage,
				                inline=True)
				embed.set_footer(text="Please find a medical professional immediately. I'm not medically trained.")
				await ctx.send(embed=embed)

A sample of the JSON file's structure (quite basic)

{
  "content": "Emergency procedures",
  "source": "St John's Ambulance",
  "method": "Copyright approval",
  "items": [
    {
      "situation": "COVID-19",
      "language": "English",
      "filetype": "pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/english/StJohnfactsheet-COVID-19.pdf"
    },
    {
      "situation": "Poster",
      "language": "Arabic",
      "filetype": ".pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/arabic/DRSABCDA4_poster.pdf"
    },
    {
      "situation": "Allergic",
      "language": "Arabic",
      "filetype": ".pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/arabic/FS_allergic.pdf"
    },
    {
      "situation": "Choking infant younger than 1 year",
      "language": "English",
      "filetype": ".pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/english/Factsheets_chokinginfant.pdf"
    },
    {
      "situation": "Concussion",
      "language": "English",
      "filetype": ".pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/english/Factsheets_concussion.pdf"
    },
    {
      "situation": "CPR on an adult",
      "language": "English",
      "filetype": ".pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/english/Factsheets_CPRadult.pdf"
    },
    {
      "situation": "CPR on infants",
      "language": "English",
      "filetype": ".pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/english/Factsheets_CPRinfants.pdf"
    },
    {
      "situation": "Diabetes",
      "language": "English",
      "filetype": ".pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/english/Factsheets_diabetes.pdf"
    },
    {
      "situation": "Drs ABCD Action Plan",
      "language": "English",
      "filetype": ".pdf",
      "url": "https://stjohn.org.au/first-aid-factsassets/uploads/factsheets/english/Factsheets_DRSABCD.pdf"
    }
  ]
}

hard to track character encoding issue in json file

In the function style_guide(), the NCA_style_guide.json file throws a character encoding exception that I can't track down manually or through parsing it through validators.

Here's a link to the Json file: NCA Style Guide

    @commands.command()
    async def style_guide(self, ctx, search_term):
        with open('NCA_style_guide.json', 'r') as reference:
            guide = json.load(reference)
        pprint(guide)
        for entry, answer in guide:
            if search_term == entry:
                result = ("> Entry: " + entry +
                          "> Usage: " + answer)
                await ctx.send(result)
Traceback (most recent call last):
  File "E:\Users\websi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "E:\KGB PROJECTS\KGB_Golem\Brook\code\cogs\news.py", line 208, in style_guide
    guide = json.load(reference)
  File "E:\Users\websi\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "E:\Users\websi\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2507: character maps to <undefined>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "E:\Users\websi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "E:\Users\websi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "E:\Users\websi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2507: character maps to <undefined>
``

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.