mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-28 16:39:06 +01:00
feat: added common name to send message
This commit is contained in:
parent
062bf9abcc
commit
14aa602161
41
main.py
41
main.py
@ -21,14 +21,18 @@ class StringCounter:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.string_map = {}
|
self.string_map = {}
|
||||||
|
|
||||||
async def update_string_map(self, string):
|
async def update_string_map(self, key, common_name):
|
||||||
await asyncio.sleep(0) # This is just to simulate asynchronous behavior
|
if key in self.string_map:
|
||||||
if string in self.string_map:
|
self.string_map[key]['count'] += 1
|
||||||
self.string_map[string] += 1
|
|
||||||
else:
|
else:
|
||||||
self.string_map[string] = 1
|
self.string_map[key] = {'common_name': common_name, 'count': 1}
|
||||||
return self.string_map
|
return self.string_map
|
||||||
|
|
||||||
|
def get_common_name(self, key):
|
||||||
|
if key in self.string_map:
|
||||||
|
return self.string_map[key]['common_name']
|
||||||
|
return None
|
||||||
|
|
||||||
def download_image(image_url):
|
def download_image(image_url):
|
||||||
# Download the image
|
# Download the image
|
||||||
image_response = requests.get(image_url)
|
image_response = requests.get(image_url)
|
||||||
@ -112,28 +116,16 @@ def extract_source_uuid(message):
|
|||||||
inside_message = message_json.get('sourceUuid', {})
|
inside_message = message_json.get('sourceUuid', {})
|
||||||
return inside_message
|
return inside_message
|
||||||
|
|
||||||
def update_string_count(string, mapping):
|
|
||||||
if string in mapping:
|
|
||||||
mapping[string] += 1
|
|
||||||
else:
|
|
||||||
mapping[string] = 1
|
|
||||||
return mapping
|
|
||||||
|
|
||||||
|
|
||||||
command_map = {
|
command_map = {
|
||||||
("!kot", "!koty", "!kots", "!cat", "!cats", "!meow", "!miau"): lambda recipient: send_image(fetch_and_download_image("https://api.thecatapi.com/v1/images/search", [0, 'url']), recipient),
|
("!kot", "!koty", "!kots", "!cat", "!cats", "!meow", "!miau", "!ᴋᴏᴛ", "!𝓴𝓸𝓽", "!𝗸𝗼𝘁"): lambda recipient: send_image(fetch_and_download_image("https://api.thecatapi.com/v1/images/search", [0, 'url']), recipient),
|
||||||
("!pies", "!psy", "!dog", "!dogs", "!woof", "!szczek"): lambda recipient: send_image(fetch_and_download_image("https://dog.ceo/api/breeds/image/random", 'message'), recipient),
|
("!pies", "!psy", "!dog", "!dogs", "!woof", "!szczek"): lambda recipient: send_image(fetch_and_download_image("https://dog.ceo/api/breeds/image/random", 'message'), recipient),
|
||||||
("!traps"): lambda recipient: send_image(download_image(((rule34Py().random_post(["trap"])).sample)), recipient)
|
("!traps"): lambda recipient: send_image(download_image(((rule34Py().random_post(["trap"])).sample)), recipient)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def extract_source_name(message):
|
||||||
def update_string_count(string, mapping):
|
message_json = message
|
||||||
if string in mapping:
|
inside_message = message_json.get('sourceName', {})
|
||||||
mapping[string] += 1
|
return inside_message
|
||||||
else:
|
|
||||||
mapping[string] = 1
|
|
||||||
return mapping
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
USER_MESSAGE_COUNT = {}
|
USER_MESSAGE_COUNT = {}
|
||||||
@ -142,8 +134,9 @@ USER_MESSAGE_COUNT = {}
|
|||||||
async def count_messages(message_content, counter):
|
async def count_messages(message_content, counter):
|
||||||
if message_content:
|
if message_content:
|
||||||
uuid = extract_source_uuid(message_content)
|
uuid = extract_source_uuid(message_content)
|
||||||
await counter.update_string_map(uuid)
|
source_name = extract_source_name(message_content)
|
||||||
|
await counter.update_string_map(uuid, source_name)
|
||||||
|
send_message(counter.string_map, PHONE_NUMBER)
|
||||||
|
|
||||||
|
|
||||||
async def scheduled_task(counter):
|
async def scheduled_task(counter):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user