feat(commands/tools/clear): add --case-insensitive
This commit is contained in:
parent
6e43b8a71a
commit
081610150d
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import arguments
|
import arguments
|
||||||
|
|
||||||
import commands
|
import commands
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
@ -31,6 +32,12 @@ async def clear(message):
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-i",
|
"-i",
|
||||||
|
"--case-insensitive",
|
||||||
|
action="store_true",
|
||||||
|
help="ignore case sensitivity when deleting messages",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-a",
|
||||||
"--author-id",
|
"--author-id",
|
||||||
type=int,
|
type=int,
|
||||||
action="append",
|
action="append",
|
||||||
@ -51,12 +58,19 @@ async def clear(message):
|
|||||||
if not (args := await parser.parse_args(message, tokens)):
|
if not (args := await parser.parse_args(message, tokens)):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
regex = None
|
||||||
|
if r := args.regex:
|
||||||
|
regex = re.compile(r, re.IGNORECASE if args.case_insensitive else 0)
|
||||||
|
|
||||||
def check(m):
|
def check(m):
|
||||||
c = []
|
c = []
|
||||||
if r := args.regex:
|
if regex:
|
||||||
c.append(re.match(r, m.content))
|
c.append(regex.search(m.content))
|
||||||
if s := args.contains:
|
if s := args.contains:
|
||||||
c.append(s in m.content)
|
if args.case_insensitive:
|
||||||
|
c.append(s.lower() in m.content.lower())
|
||||||
|
else:
|
||||||
|
c.append(s in m.content)
|
||||||
if i := args.author_id:
|
if i := args.author_id:
|
||||||
c.append(m.author.id in i)
|
c.append(m.author.id in i)
|
||||||
if args.reactions:
|
if args.reactions:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user