%words improvement
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
* %react - rank users by their reactions
|
* %react - rank users by their reactions
|
||||||
* arguments:
|
* arguments:
|
||||||
* <n> - top <n> messages, default is 10
|
* <n> - top <n> messages, default is 10
|
||||||
* %words - rank words by their usage
|
* %words - (BETA) rank words by their usage
|
||||||
* arguments:
|
* arguments:
|
||||||
* <n> - words containings <n> or more letters, default is 3
|
* <n> - words containings <n> or more letters, default is 3
|
||||||
* <n2> - top <n2> words, default is 10
|
* <n2> - top <n2> words, default is 10
|
||||||
@@ -104,6 +104,8 @@ python3 src/main.py
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
* **v1.13**
|
||||||
|
* improved scan `%words`
|
||||||
* **v1.12**
|
* **v1.12**
|
||||||
* more scans: `%words`
|
* more scans: `%words`
|
||||||
* concurrent `fast` analysis
|
* concurrent `fast` analysis
|
||||||
|
|||||||
+6
-6
@@ -45,6 +45,12 @@ bot.register_command(
|
|||||||
"cancel: stop current analysis (not launched with fast)",
|
"cancel: stop current analysis (not launched with fast)",
|
||||||
"```\n" + "%cancel: Stop current analysis (not launched with fast)\n" + "```",
|
"```\n" + "%cancel: Stop current analysis (not launched with fast)\n" + "```",
|
||||||
)
|
)
|
||||||
|
bot.register_command(
|
||||||
|
"words",
|
||||||
|
lambda *args: WordsScanner().compute(*args),
|
||||||
|
"words: (BETA) rank words by their usage",
|
||||||
|
WordsScanner.help(),
|
||||||
|
)
|
||||||
bot.register_command(
|
bot.register_command(
|
||||||
"last",
|
"last",
|
||||||
lambda *args: LastScanner().compute(*args),
|
lambda *args: LastScanner().compute(*args),
|
||||||
@@ -63,12 +69,6 @@ bot.register_command(
|
|||||||
"first: read first message",
|
"first: read first message",
|
||||||
FirstScanner.help(),
|
FirstScanner.help(),
|
||||||
)
|
)
|
||||||
bot.register_command(
|
|
||||||
"words",
|
|
||||||
lambda *args: WordsScanner().compute(*args),
|
|
||||||
"words: rank words by their usage",
|
|
||||||
WordsScanner.help(),
|
|
||||||
)
|
|
||||||
bot.register_command(
|
bot.register_command(
|
||||||
"mentioned",
|
"mentioned",
|
||||||
lambda *args: MentionedScanner().compute(*args),
|
lambda *args: MentionedScanner().compute(*args),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class WordsScanner(Scanner):
|
|||||||
def help() -> str:
|
def help() -> str:
|
||||||
return (
|
return (
|
||||||
"```\n"
|
"```\n"
|
||||||
+ "%words: Rank words by their usage\n"
|
+ "%words: (BETA) Rank words by their usage\n"
|
||||||
+ "arguments:\n"
|
+ "arguments:\n"
|
||||||
+ COMMON_HELP_ARGS
|
+ COMMON_HELP_ARGS
|
||||||
+ "* <n> - words containings <n> or more letters, default is 3\n"
|
+ "* <n> - words containings <n> or more letters, default is 3\n"
|
||||||
@@ -104,16 +104,13 @@ class WordsScanner(Scanner):
|
|||||||
or message.author in raw_members
|
or message.author in raw_members
|
||||||
):
|
):
|
||||||
impacted = True
|
impacted = True
|
||||||
content = " ".join(
|
content = message.content
|
||||||
[
|
content = re.sub(r"```.+```", "", content, flags=re.DOTALL)
|
||||||
block
|
content = re.sub(r"`.+`", "", content, flags=re.DOTALL)
|
||||||
for block in message.content.split()
|
content = re.sub(r"\w+:\/\/[^ ]+", "", content)
|
||||||
if not re.match(r"^\w+:\/\/", block)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
for word in re.split("[^\w\-':]", content):
|
for word in re.split("[^\w\-':]", content):
|
||||||
m = re.match(
|
m = re.match(
|
||||||
r"(?!^:\w+:$)^[^\w]*((?![\d_])\w.*(?![\d_])\w)[^\w]*$", word
|
r"(?!^:\w+:$)^[^\w]*((?![\d_])\w[\w\-']*(?![\d_])\w)[^\w]*$", word
|
||||||
)
|
)
|
||||||
if m:
|
if m:
|
||||||
word = m[1].lower()
|
word = m[1].lower()
|
||||||
@@ -126,7 +123,5 @@ class WordsScanner(Scanner):
|
|||||||
words[word] = words[word + case]
|
words[word] = words[word + case]
|
||||||
del words[word + case]
|
del words[word + case]
|
||||||
break
|
break
|
||||||
words[word].update_use(
|
words[word].update_use(1, message.created_at)
|
||||||
message.content.count(word), message.created_at
|
|
||||||
)
|
|
||||||
return impacted
|
return impacted
|
||||||
|
|||||||
Reference in New Issue
Block a user