Skip to content

Instantly share code, notes, and snippets.

@Hackerjef
Last active June 12, 2021 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hackerjef/de943e03987c2cf1d07ac6282a92d1ff to your computer and use it in GitHub Desktop.
Save Hackerjef/de943e03987c2cf1d07ac6282a92d1ff to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# MIT License
# Copyright(c)2020 Nadie#0063
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files(the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import sys
import argparse
import re
import urllib
inbox = re.compile(r":inbox_tray:")
idre = re.compile(r"\(([^\)]+)\)")
table = str.maketrans(dict.fromkeys("()"))
def fmtReason(reason):
return "-r {}".format('\"{}\"'.format(reason) if len(reason.split()) > 1 else reason)
def GrabIds(data):
for line in data:
if (inbox.match(line)):
yield idre.search(line)[0].translate(table)
def chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i+n]
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Grab Ids from Aperture (rowboat clone) modlog to be mbanned')
parser.add_argument('-u', "--url", default=None, help='to grab from url', required=False)
parser.add_argument('-f', "--file", default=None, type=argparse.FileType('r', encoding='UTF-8'), help='to grab from a custom file', required=False)
parser.add_argument('-l', "--list_ids", help='to list ids insted of mban format', action='store_true')
parser.add_argument('-t', "--command", default="mban", help="mban or mkick or what other command is there")
parser.add_argument('-p', "--prefix", default="!", help="to set prefix")
parser.add_argument('-r', "--reason", default=None, help="if command as a -r set a reason")
args = parser.parse_args()
if args.url:
f = urllib.request.urlopen(args.url)
data = f.read().decode('utf-8')
else:
try:
data = args.file or open("modlog.txt", "r", encoding="utf8")
except FileNotFoundError:
print("log not arged or Modlog.txt not found")
sys.exit()
ids = list(GrabIds([line.rstrip('\n') for line in data]))
print(f"Number of ids found: {len(ids)}")
if args.list_ids:
for id in ids:
print(id)
else:
seperated_ids = list(chunks(ids, 38))
for ids in seperated_ids:
print(f"{args.prefix}{args.command} {' '.join(ids)} {fmtReason(args.reason) if args.reason else ''}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment